ActivityLogic.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\api\logic;
  3. use app\adminapi\logic\property\PropertyUserLogic;
  4. use app\common\logic\BaseLogic;
  5. use app\common\model\coupon\CouponRules;
  6. use app\common\model\goods\Goods;
  7. use app\common\model\goods_category\GoodsCategory;
  8. use app\common\model\property\PropertyActivity;
  9. use app\common\model\user\User;
  10. use think\facade\Db;
  11. use think\facade\Log;
  12. /**
  13. * 活动逻辑处理
  14. * Class ActivityLogic
  15. * @package app\api\logic
  16. */
  17. class ActivityLogic extends BaseLogic
  18. {
  19. public static function getHomepageByActivityId($params){
  20. $res = [];
  21. try{
  22. $propertyActivity = PropertyActivity::with(['propertyHeadInfo'])->where('id',$params['property_activity_id'])->findOrEmpty();
  23. if($propertyActivity->isEmpty()){
  24. throw new \Exception('活动不存在');
  25. }
  26. if(!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()){
  27. throw new \Exception('活动未开始');
  28. }
  29. if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
  30. throw new \Exception('活动已结束');
  31. }
  32. if($params['user_id']){
  33. // property_head_id householder_mobile householder_name address
  34. $userInfo = User::where('id',$params['user_id'])->findOrEmpty();
  35. if ($userInfo->isEmpty()) {
  36. // 检查/注册
  37. PropertyUserLogic::getPropertyUserIdByMobile([
  38. 'householder_mobile' => $userInfo['mobile'],
  39. 'householder_name' => $userInfo['real_name'],
  40. 'address' => '',
  41. 'property_head_id' => $propertyActivity['property_head_id']
  42. ]);
  43. }
  44. }
  45. $res['activity_info'] = $propertyActivity->toArray();
  46. $res['coupons'] = CouponRules::where('property_activity_id',$params['property_activity_id'])
  47. ->select()
  48. ->toArray();
  49. $res['goods'] = Goods::where('property_activity_id',$params['property_activity_id'])
  50. ->where('is_agent',1)
  51. ->visible(['id','goods_name','goods_image','base_service_fee','service_total','service_fee','goods_type'])
  52. ->order('is_recommend desc')
  53. ->select()
  54. ->toArray();
  55. return $res;
  56. }catch(\Exception $e){
  57. throw new \Exception($e->getMessage());
  58. }
  59. }
  60. public static function createPropertyOrder($params,$serviceOrder){
  61. try{
  62. // 判断商品是否为 代理活动商品
  63. $goods = Goods::findOrEmpty($params['goods_id']);
  64. if($goods->isEmpty()){
  65. throw new \Exception('产品不存在!');
  66. }
  67. if($goods->property_activity_id > 0){
  68. $propertyActivity = PropertyActivity::findOrEmpty($goods->property_activity_id);
  69. if($propertyActivity->isEmpty()){
  70. throw new \Exception('活动不存在');
  71. }
  72. if(!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()){
  73. throw new \Exception('活动未开始');
  74. }
  75. if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
  76. throw new \Exception('活动已结束');
  77. }
  78. // 生成代理单 user_info
  79. // remark address property_head_id householder_name householder_mobile
  80. $result = PropertyOrderLogic::add(array_merge($params,[
  81. 'property_head_id' => $propertyActivity['property_head_id'],
  82. 'householder_mobile' => $params['user_info']['mobile'],
  83. 'householder_name' => $params['user_info']['real_name'],
  84. 'address' => $params['address'],
  85. 'remark' => '',
  86. 'order_status' => 1,
  87. 'work_id' => $serviceOrder['work_id'],
  88. ]));
  89. if($result === false){
  90. throw new \Exception('生成代理单失败');
  91. }
  92. }
  93. return true;
  94. }catch(\Exception $e){
  95. throw new \Exception($e->getMessage());
  96. }
  97. }
  98. }