Esempio n. 1
0
 /**
  * @author song
  * 提屁股 成功修改状态接口
  * @param int  $supportid 支持人id
  * @param int $supnum 踢屁股次数
  *
  * @return json
  * */
 public function actionGamesuccess()
 {
     //判断登陆
     $user = PublicLibrary::is_login();
     if ($user && $user['uid'] != 'weixin' && PublicLibrary::is_ajax()) {
         $date = Yii::$app->request->post();
         $supportid = isset($date['supportid']) ? intval($date['supportid']) : 0;
         $supnum = isset($date['supnum']) ? intval($date['supnum']) : 0;
         $msupport = new BaiyingSupport();
         $supportone = $msupport->pk($supportid);
         if ($supportone && $supportone['support_status'] == BaiyingSupport::SUPPORT_STATUS_DEF) {
             if ($supnum > BaiyingSupport::SUPPORT_STATAR) {
                 $mshare = new BaiyingShare();
                 //查询分享人uid
                 $oldres = $mshare->pk($supportone['shareid']);
                 $rel_id = $oldres['rel_id'];
                 //判断活动状态
                 $mactpro = new ActivityProduct();
                 $productattr = $mactpro->getDetailBypk($rel_id);
                 if ($productattr['status'] != ActivityProduct::STATUS_VERIFY_THROUGH) {
                     echo "<script>alert('活动已结束!'),window.location.href='/baiying/userproduct';</script>";
                     exit;
                 }
                 //查询该分享人所有的分享列表
                 $sharelist = $mshare->getSharelistByuid('', $oldres['uid'], ActivityBase::APPLY_BAIYING);
                 foreach ($sharelist as $key => $val) {
                     $sarr[] = $val['id'];
                 }
                 //查询当前用户支持成功的 记录
                 $usersuplist = $msupport->getSupportlist('', $user['uid'], BaiyingSupport::SUPPORT_STATUS_SUCCE);
                 foreach ($usersuplist as $key => $val) {
                     $uresanduser = $mshare->pk($val['shareid']);
                     //当前用户支持的产品的发布用户 等于 要支持订单的发布者
                     if ($uresanduser['uid'] == $oldres['uid']) {
                         $uarr[] = $val['shareid'];
                     }
                 }
                 if (isset($sarr) && isset($uarr)) {
                     $insec = array_intersect($sarr, $uarr);
                 }
                 //                $cc = isset($insec)?$insec:'1';
                 //                echo '<pre>';
                 //                print_r($cc);
                 if (isset($insec) && is_array($insec)) {
                 } else {
                     //增加分享支持统计数
                     $shafu = $mshare->addSharenum($supportone['shareid']);
                 }
                 $shareone = $mshare->pk($supportone['shareid']);
                 //支持数大于标准(30),且状态为1 修改支付状态
                 if ($shareone['share_num'] >= BaiyingShare::SHARE_STANDARD && $shareone['share_status'] == BaiyingShare::SHARE_STATUS_DEF) {
                     $sharecontent['id'] = $supportone['shareid'];
                     //商品剩余不足 状态修改成 售罄
                     //支付成功的分享
                     $succnum = $mshare->getcountnum($shareone['rel_id'], BaiyingShare::SHARE_STATUS_PAY);
                     //商品属性
                     $mapattrval = new ActivityProductAttrVal();
                     $acprattr = $mapattrval->getRealAttrVals($shareone['rel_id'], ActivityBase::APPLY_BAIYING);
                     if ($succnum >= $acprattr['supply_num']['attr_val']) {
                         $sharecontent['share_status'] = BaiyingShare::SHARE_OUT;
                     } else {
                         $sharecontent['share_status'] = BaiyingShare::SHARE_STATUS_SUCCE;
                     }
                     $res = $mshare->store($sharecontent);
                 }
                 $upcontent['support_status'] = BaiyingSupport::SUPPORT_STATUS_SUCCE;
             }
             //更新支持提屁股次数和 状态
             $upcontent['id'] = $supportid;
             $upcontent['uid'] = isset($user['uid']) ? $user['uid'] : '';
             $upcontent['mobile'] = isset($user['mobile']) ? $user['mobile'] : '';
             if ($supnum > $supportone['sup_num']) {
                 $upcontent['sup_num'] = $supnum;
             }
             $supfu = $msupport->store($upcontent);
             if ($supfu) {
                 echo PublicLibrary::format_res_encode('0', 'success', 'f**k');
             } else {
                 echo PublicLibrary::format_res_encode('1001', 'save error!');
             }
         } else {
             $upcontent['id'] = $supportid;
             if ($supnum > $supportone['sup_num']) {
                 $upcontent['sup_num'] = $supnum;
             }
             $upcontent['support_status'] = BaiyingSupport::SUPPORT_STATUS_SUCCE;
             $supfu = $msupport->store($upcontent);
             if ($supfu) {
                 echo PublicLibrary::format_res_encode('01', 'supnum up success!');
             } else {
                 echo PublicLibrary::format_res_encode('1003', 'supnum up error!');
             }
         }
     } else {
         echo PublicLibrary::format_res_encode('1001', 'the user no login or no ajax!');
         exit;
     }
 }