...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\admin\model\Collection;
|
|
|
use app\admin\model\Rcoupon;
|
|
|
use app\common\controller\Api;
|
|
|
use fast\Http;
|
|
|
use think\Validate;
|
...
|
...
|
@@ -215,6 +216,8 @@ class User extends Api |
|
|
}else{
|
|
|
$res = $collectionModel->create(['g_id'=>$goods_id,'uid'=>$this->uid]);
|
|
|
if($res){
|
|
|
$goodsModel = new \app\admin\model\Goods();
|
|
|
$goodsModel->where(['id'=>$goods_id])->setInc('collections',1);
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
$this->error('失败');
|
...
|
...
|
@@ -252,6 +255,8 @@ class User extends Api |
|
|
$collectionModel = new Collection();
|
|
|
$res = $collectionModel->where(['uid'=>$this->uid,'g_id'=>$goods_id])->delete();
|
|
|
if($res){
|
|
|
$goodsModel = new \app\admin\model\Goods();
|
|
|
$goodsModel->where(['id'=>$goods_id])->setDec('collections',1);
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
$this->error('失败');
|
...
|
...
|
@@ -449,4 +454,65 @@ class User extends Api |
|
|
$this->error('请求方式错误');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (分享获取礼包)
|
|
|
* @ApiSummary (分享获取礼包)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/share)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
*
|
|
|
* @ApiParams (name="share_uid", type="inter", required=true, description="分享人uid")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1571037179",
|
|
|
"data": null
|
|
|
})
|
|
|
*/
|
|
|
public function share(){
|
|
|
if($this->request->isPost()){
|
|
|
$share_uid = $this->request->post('share_uid');
|
|
|
$rule = config('verify.share');
|
|
|
$validate = new Validate($rule['rule'],$rule['msg']);
|
|
|
if (!$validate->check(['share_uid'=>$share_uid])) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
|
|
|
$rCouponModel = new Rcoupon();
|
|
|
//查询分享人已领取优惠券
|
|
|
$receive = Common::selectWhereData('rcoupon',['uid'=>$share_uid],'id,c_id');
|
|
|
$receive_s = array_column($receive,'c_id');
|
|
|
//查询分享人优惠券
|
|
|
$res_coupon = Common::selectWhereData('coupon',['gift'=>1,'end_time'=>['>',time()]],'id');
|
|
|
$res_coupon = array_column($res_coupon,'id');
|
|
|
$res = array_diff($res_coupon,$receive_s);//数组1不存在数组2中的数组
|
|
|
$arr = [];
|
|
|
foreach($res as $key=>$value){
|
|
|
$arr[$key]['uid'] = $share_uid;
|
|
|
$arr[$key]['c_id'] = $value;
|
|
|
$arr[$key]['is_share'] = 1;
|
|
|
}
|
|
|
$rCouponModel->saveAll($arr);
|
|
|
|
|
|
//查询被分享人已领取优惠券
|
|
|
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
|
|
|
$receive_s = array_column($receive,'c_id');
|
|
|
//查询分享人优惠券
|
|
|
$res_coupon = Common::selectWhereData('coupon',['gift'=>2,'end_time'=>['>',time()]],'id');
|
|
|
$res_coupon = array_column($res_coupon,'id');
|
|
|
$res = array_diff($res_coupon,$receive_s);//数组1不存在数组2中的数组
|
|
|
$arr1 = [];
|
|
|
foreach($res as $key=>$value){
|
|
|
$arr1[$key]['uid'] = $this->uid;
|
|
|
$arr1[$key]['c_id'] = $value;
|
|
|
$arr1[$key]['is_share'] = 1;
|
|
|
}
|
|
|
$rCouponModel->saveAll($arr1);
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
$this->error('请求方式错误');
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|