ActivityLogic.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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::order(['category_type' => 'desc'])
  50. ->where('property_activity_id',$params['property_activity_id'])
  51. ->where('is_agent',1)
  52. ->visible(['id','goods_name','goods_image','base_service_fee','service_total','service_fee'])
  53. ->order('is_recommend desc')
  54. ->select()
  55. ->toArray();
  56. return $res;
  57. }catch(\Exception $e){
  58. throw new \Exception($e->getMessage());
  59. }
  60. }
  61. public static function createPropertyOrder($params){
  62. try{
  63. // 判断商品是否为 代理活动商品
  64. $goods = Goods::findOrEmpty($params['goods_id']);
  65. if($goods->isEmpty()){
  66. throw new \Exception('产品不存在!');
  67. }
  68. if($goods->property_activity_id > 0){
  69. $propertyActivity = PropertyActivity::findOrEmpty($goods->property_activity_id);
  70. if($propertyActivity->isEmpty()){
  71. throw new \Exception('活动不存在');
  72. }
  73. if(!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()){
  74. throw new \Exception('活动未开始');
  75. }
  76. if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
  77. throw new \Exception('活动已结束');
  78. }
  79. // 生成代理单 user_info
  80. // remark address property_head_id householder_name householder_mobile
  81. $result = PropertyOrderLogic::add(array_merge($params,[
  82. 'property_head_id' => $propertyActivity['property_head_id'],
  83. 'householder_mobile' => $params['user_info']['mobile'],
  84. 'householder_name' => $params['user_info']['real_name'],
  85. 'address' => $params['address'],
  86. 'remark' => '',
  87. ]));
  88. if($result === false){
  89. throw new \Exception('生成代理单失败');
  90. }
  91. }
  92. return true;
  93. }catch(\Exception $e){
  94. throw new \Exception($e->getMessage());
  95. }
  96. }
  97. }