Пример #1
0
 /**
  * 使用优惠券
  * @Param Int $storeCouponId 店铺优惠券ID
  * @method GET
  * @Return JOSN 返回执行json结果 ,message=0表示成功
  */
 public function actionUsecoupon()
 {
     $request = \Yii::$app->request;
     $userId = intval($request->get('userId', 0));
     if (EasyHelpers::encrypty($userId, \Yii::$app->params['key']) != $request->get('usign', 0)) {
         return ['code' => 5, 'msg' => '非法数据'];
     }
     $storeCouponId = intval($request->get('storeCouponId', 0));
     if (!$storeCouponId) {
         return ['code' => 4, 'msg' => '数据非法'];
     }
     $data = StoreCoupon::getStoreCoupon($storeCouponId, $userId);
     if (!$data) {
         return ['code' => 3, 'msg' => '优惠券不存在'];
     }
     if (!StoreCoupon::checkCoupon($storeCouponId, $userId)) {
         return ['code' => 6, 'msg' => '您没有这张优惠券'];
     }
     $miaoCoin = new MiaoCoin();
     $miaoCoin->userId = $data[0]['userId'];
     $miaoCoin->byWay = 'coupon';
     $miaoCoin->amount = $data[0]['couponPrice'];
     $miaoCoin->used = 'input';
     $miaoCoin->couponId = $data[0]['couponId'];
     if ($miaoCoin->save()) {
         $res = StoreCoupon::findOne(['storeCouponId' => $storeCouponId])->delete();
         if ($res !== false) {
             return ['code' => 0, 'msg' => '优惠券使用成功', 'data' => ['miaoCoin' => $miaoCoin->amount]];
         }
     }
     return ['code' => 2, 'msg' => '优惠券使用失败,请重试', 'data' => []];
 }
Пример #2
0
 /**
  * 获取产品信息
  */
 public function actionIndex()
 {
     //3SCJEJSEZB
     $prdouctId = \Yii::$app->request->get('code', 0);
     if (!intval($prdouctId)) {
         return ['code' => 4, 'msg' => 'undefine parameter', 'data' => []];
     }
     $prdouctId = EasyHelpers::pidDecrypt($prdouctId);
     $product = Product::getProductById($prdouctId);
     if (!$product) {
         return ['code' => 3, 'msg' => 'data is not exist', 'data' => []];
     }
     $mcoin = MiaoCoin::getMiaoCoin($product['ownid']);
     //       if($mcoin<1) return ['code'=>4,'msg'=>'balance is insufficient','data'=>[]];
     //       if($product['status']!='online') return ['code'=>5,'msg'=>'This product had down shelf','data'=>[]];
     $store = Store::getStoreInfo($product['ownid']);
     $res = ['seller' => $store->storeName, 'storePhone' => $store->tel, 'storeMobile' => $store->mobile, 'storeAddress' => $store->address, 'storeLogo' => EasyHelpers::getStoreLogoUrl($store->logo)];
     $exclude = ['sku', 'hiddenBrand', 'ownid', 'from', 'createTime', 'updateTime', 'qrImage', 'originName'];
     foreach ($product as $key => $value) {
         if (!$value || in_array($key, $exclude)) {
             continue;
         }
         if ($key == "size") {
             $tempSize = [];
             $tempSize = explode('*', $value);
             $res['productLength'] = $tempSize[0];
             $res['productWidth'] = $tempSize[1];
             $res['productHeight'] = $tempSize[2];
             continue;
         }
         if ($key == 'productId') {
             $res['productId'] = EasyHelpers::pidEncrypt($value);
             continue;
         }
         if ($key == 'newName') {
             $res['productImageName'] = $value;
             continue;
         }
         if ('status' == $key) {
             $res['hasComplete'] = 'offline' == $value || 'online' == $value ? true : false;
             continue;
         }
         if ('material' == $key) {
             $res['productMaterial'] = $value;
             continue;
         }
         $res[$key] = $value;
     }
     if ($product['type'] == 'virtual') {
         $res['productDescript'] = $product['re_product']['productDescript'];
         $res['productImage'] = \Yii::$app->sysConfig->getConfig()->default['imageDomain'] . 'product/thumb/' . $product['re_product']['newName'];
         $productFlie = Product::getFileName($product['re_product']['productId']);
     } else {
         $res['productImage'] = \Yii::$app->sysConfig->getConfig()->default['imageDomain'] . 'product/thumb/' . $product['newName'];
         $productFlie = Product::getFileName($prdouctId);
     }
     $res['favorite'] = Favorite::getCount($prdouctId);
     $res['hasView'] = $productFlie ? true : false;
     return ['code' => 0, 'msg' => 'success', 'data' => $res];
 }
Пример #3
0
 /**
  * 改变产品状态
  */
 public function actionSavestatus()
 {
     $request = \Yii::$app->request;
     $productId = intval($request->get('productId', ''));
     $userId = $request->_get('userId', 0);
     $usign = $request->_get('usign', '');
     if ($usign != EasyHelpers::encrypty($userId, \Yii::$app->params['key'])) {
         return ['code' => 5, 'msg' => '非法数据'];
     }
     if (!$productId) {
         return ['code' => 2, 'msg' => '数据非法'];
     }
     $status = $request->_get('status', 'waiting');
     if (!in_array($status, \Yii::$app->params['productStatus'])) {
         $status = 'waiting';
     }
     if ($status == 'online' && !Product::checkChangeable($productId)) {
         //return ['code' => 1, 'msg' => '系统下架商品不可上架'];
     }
     if ($status == 'online' && !MiaoCoin::getMiaoCoin($userId)) {
         return ['code' => 1, 'msg' => '瞄币不足,请先到账户信息页面进行充值'];
     }
     if ($status == 'online') {
         $product = Product::findOne(['productId' => $productId]);
         $ownId = $product ? $product['ownid'] : '';
         if ($userId != $ownId) {
             return ['code' => 6, 'msg' => '数据非法', 'data' => []];
         }
         $checkFN = \master\models\Store::checkFileNumberOnline($userId);
         if (!$checkFN) {
             return ['code' => 2, 'msg' => '模具空间不足'];
         }
     }
     $model = new Product();
     $res = $model->saveStatus($productId, $status);
     if ($res !== false) {
         return ['code' => 0, 'msg' => '操作成功'];
     } else {
         return ['code' => 2, 'msg' => '操作失败,请重试'];
     }
 }
Пример #4
0
 /**
  * 保存用户对产品的点击数量;仅对匿名用户有效;
  * @param int $pid  产品ID
  * @param string $userIdentity 用户识别码
  */
 public static function saveCilck($pid, $userIdentity = '')
 {
     if (!intval($pid)) {
         return false;
     }
     $gapTime = \Yii::$app->params['gapTime'];
     $isInsert = false;
     $uid = User::getAnonymousId($userIdentity);
     if ($uid) {
         $sql = "SELECT IF( ( UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(createTime) ) >" . $gapTime . " , 'true', 'false' ) as result FROM product_click WHERE userId=" . $uid . " AND userType='anonymous' ORDER BY createTime DESC LIMIT 1";
         $resData = static::getDb()->createCommand($sql)->queryScalar();
         if ($resData != 'false') {
             $isInsert = true;
         }
     }
     $pownId = Product::getOwnId($pid);
     if ($isInsert && $pownId) {
         static::getDb()->createCommand()->insert(static::tableName(), array('productId' => $pid, 'userId' => $uid, 'userType' => 'anonymous'))->execute();
         MiaoCoin::updateClickM(static::getDb()->getLastInsertID(), $pownId);
         User::updateCacheMcoin(User::getSoreId($pownId), 1, 'output');
         return true;
     }
     return false;
 }