| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\api\logic;
- use app\adminapi\logic\property\PropertyUserLogic;
- use app\common\logic\BaseLogic;
- use app\common\model\coupon\CouponRules;
- use app\common\model\goods\Goods;
- use app\common\model\goods_category\GoodsCategory;
- use app\common\model\property\PropertyActivity;
- use app\common\model\user\User;
- use think\facade\Db;
- use think\facade\Log;
- /**
- * 活动逻辑处理
- * Class ActivityLogic
- * @package app\api\logic
- */
- class ActivityLogic extends BaseLogic
- {
- public static function getHomepageByActivityId($params){
- $res = [];
- try{
- $propertyActivity = PropertyActivity::with(['propertyHeadInfo'])->where('id',$params['property_activity_id'])->findOrEmpty();
- if($propertyActivity->isEmpty()){
- throw new \Exception('活动不存在');
- }
- if(!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()){
- throw new \Exception('活动未开始');
- }
- if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
- throw new \Exception('活动已结束');
- }
- Log::info('getHomepageByActivityId params:'.json_encode($params));
- if($params['user_id']){
- // property_head_id householder_mobile householder_name address
- $userInfo = User::where('id',$params['user_id'])->findOrEmpty();
- if (!$userInfo->isEmpty()) {
- // 检查/注册
- Log::info('getHomepageByActivityId params-102:'.json_encode([$userInfo]));
- PropertyUserLogic::getPropertyUserIdByMobile([
- 'householder_mobile' => $userInfo['mobile'],
- 'householder_name' => $userInfo['real_name'],
- 'address' => '',
- 'property_head_id' => $propertyActivity['property_head_id']
- ]);
- }
- }
- $res['activity_info'] = $propertyActivity->toArray();
- $res['coupons'] = CouponRules::with(['couponCategoryOne'])->where('property_activity_id',$params['property_activity_id'])
- ->select()
- ->toArray();
- foreach ($res['coupons'] as &$coupon) {
- $coupon['goods_category_id'] = $coupon['couponCategoryOne']['goods_category_id'];
- }
- $res['goods'] = Goods::where('property_activity_id',$params['property_activity_id'])
- ->where('is_agent',1)
- ->visible(['id','goods_name','goods_image','base_service_fee','service_total','service_fee','goods_type'])
- ->order('is_recommend desc')
- ->select()
- ->toArray();
- return $res;
- }catch(\Exception $e){
- throw new \Exception($e->getMessage());
- }
- }
- public static function createPropertyOrder($params,$serviceOrder){
- try{
- // 判断商品是否为 代理活动商品
- $goods = Goods::findOrEmpty($params['goods_id']);
- if($goods->isEmpty()){
- throw new \Exception('产品不存在!');
- }
- if($goods->property_activity_id > 0){
- $propertyActivity = PropertyActivity::findOrEmpty($goods->property_activity_id);
- if($propertyActivity->isEmpty()){
- throw new \Exception('活动不存在');
- }
- if(!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()){
- throw new \Exception('活动未开始');
- }
- if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
- throw new \Exception('活动已结束');
- }
- // 生成代理单 user_info
- // remark address property_head_id householder_name householder_mobile
- $result = PropertyOrderLogic::add(array_merge($params,[
- 'property_head_id' => $propertyActivity['property_head_id'],
- 'householder_mobile' => $params['user_info']['mobile'],
- 'householder_name' => $params['user_info']['real_name'],
- 'address' => $params['address'],
- 'remark' => '',
- 'order_status' => 1,
- 'work_id' => $serviceOrder['work_id'],
- ]));
- if($result === false){
- throw new \Exception('生成代理单失败');
- }
- }
- return true;
- }catch(\Exception $e){
- throw new \Exception($e->getMessage());
- }
- }
- }
|