/** * 获取产品信息 */ 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]; }
/** * 改变产品状态 */ 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' => '操作失败,请重试']; } }