page = 1; $merchantForm->limit = 1; $merchantForm->setSaasStoreCloudId(); if (!$merchantForm->token_stroe_cloud_id) { $this->asJson([ 'code' => 1, 'msg' => '未查到云仓用户' ]); } $balance = $merchantForm->mchGetBalanceLog(); $order = OrderListForm::getCountData(get_saas_user_id()); $item = get_saas_purchase_store_cloud(); $mch = $item ? $item->name : ''; $access_token = get_params('access_token'); $saas_user_model = SaasUser::findOne(['access_token' => $access_token]); $admin = Admin::findOne(['saas_user_id' => $saas_user_model->id, 'is_delete' => 0, 'type' => 'store']); $store = Store::findOne($admin->type_id); //联盟券部分 $query = SaaSLeaguePriceLog::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'role' => SaaSLeaguePriceLog::ROLE_STORE]) ->andWhere(['AND', ['>=', 'addtime', strtotime(date('Ymd'))], ['<=', 'addtime', time()]]); //今日收入 $today_price_query = clone $query; $today_price= $today_price_query->andWhere(['send_or_take_type' => 0])->sum('league_price') ?: 0; //今日赠送 $today_send_price_query = clone $query; $today_send_price = $today_send_price_query->andWhere(['type' => 0])->sum('league_price') ?: 0; //今日支出 $today_out_price_query = clone $query; $today_out_price = $today_out_price_query->andWhere(['send_or_take_type' => 1])->sum('league_price') ?: 0; //列表 $price_list = $query->select('id, type, send_or_take_type, league_price, addtime')->orderBy('addtime desc')->asArray()->all(); foreach ($price_list as &$item) { $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']); $item['type'] = (int)$item['type']; $item['send_or_take_type'] = (int)$item['send_or_take_type']; } $league_price = [ 'price' => $today_price, 'send_price' => $today_send_price, 'out_price' => $today_out_price ]; return $this->asJson([ 'code' => 0, 'data' => [ 'user' => get_saas_user(), 'mch' => $mch, 'balance' => $balance['data']['mch'], 'league_price' => $store->league_price, 'order' => $order, 'today_league_price' => $league_price, 'price_list' => $price_list ] ]); } /** * */ public function actionBalance() { $merchantForm = new MerchantForm(); $merchantForm->attributes = post_params(); $merchantForm->setSaasStoreCloudId(); return $this->asJson($merchantForm->mchGetBalanceLog()); } public function actionLeague() { $page = post_params('page'); $access_token = post_params('access_token'); $saas_user_model = SaasUser::findOne(['access_token' => $access_token]); $saas_user_id = $saas_user_model->id; $admin = Admin::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'type' => 'store']); $store = Store::findOne($admin->type_id); $query= RechargeReOrder::find()->where(['store_id' => $store->id,'is_pay' => 1]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'page' => $page - 1, 'pageSize' => 10]); $list = $query->limit($pagination->limit)->offset($pagination->offset)->asArray()->orderBy('id DESC')->all(); foreach ($list as & $arr) { $arr['desc'] = '充值联盟券'. $arr['league_price'] . '元'; $arr['price'] = $arr['pay_price']; $arr['addtime'] = date('Y-m-d H:i:s' ,$arr['created_at']); } return $this->asJson([ 'code' => 0, 'sql' => $query, 'msg' => '查找成功', 'count' => $count, 'data' => ['list' => $list] ]); } /** * 充值提交 */ public function actionBalanceSubmit() { $form = new \app\modules\alliance\models\purchase\BalanceForm(); $store_id = get_saas_purchase_store_id(); $form->store_id = $store_id; $form->saas_id = get_saas_user_id(); $form->user = get_saas_user(); $form->attributes = get_params(); return $this->asJson($form->payData()); } public function actionLeagueSubmit() { $form = new \app\modules\alliance\models\purchase\BalanceForm(); $store_id = get_saas_purchase_store_id(); $form->store_id = $store_id; $form->saas_id = get_saas_user_id(); $form->user = get_saas_user(); $form->attributes = get_params(); return $this->asJson($form->payDataLeague()); } public function actionBalanceSubmit2() { $order = \app\models\PurchaseReOrder::findOne(['order_no' => 'PR20221019154533294742']); $form = new \app\modules\alliance\models\purchase\BalanceForm(); $form->store_id = $order->store_id; $form->saas_id = $order->saas_id; $form->order = $order; $result = $form->storeSubmitRecharge(); var_dump($result); } /** * 商户商品分类列表 */ public function actionMchCatList() { $is_show = get_params('is_show',Cat::IS_SHOW_TRUE); $store_id = get_saas_purchase_store_id(); $list = Cat::getCatList($store_id, $is_show, 0, 0); return $this->asJson([ 'code' => 0, 'data' => [ 'list' => $list ] ]); } /** * 云仓商品分类列表 */ public function actionCatList() { $form = new PlatformForm(); $form->attributes = get_params(); $form->is_show = get_params('is_show',Cat::IS_SHOW_TRUE); $this->asJson($form->getGoodsCatList()); } /** * 云仓商品分类列表 */ public function actionCatListChild() { $form = new PlatformForm(); $form->attributes = get_params(); $this->asJson($form->getCatListChildren()); } /** * 商品列表 */ public function actionGoodsInfo() { $form = new PlatformForm(); $form->attributes = get_params(); $goods = $form->goodsInfo(); $hasFav = PurchaseFavorite::findOne(['goods_id'=>get_params('id', 0), 'saas_id' => get_saas_user_id(), 'is_delete' => 0]); $goods['is_favorite'] = empty($hasFav) ? 0 : 1; // 获取客服id $goods['kefu_id'] = ''; if (isset($goods['data']['list'][0]['supplier']['id'])) { $supplier = Supplier::find()->where(['cloud_supplier_id' => $goods['data']['list'][0]['supplier']['id']])->one(); if ($supplier) { $goods['data']['list'][0] = \app\modules\admin\models\jushuitan\JuShuiTanForm::syncSupplierJstGoodsQty($supplier->id, $goods['data']['list'][0]); $goods['supplier'] = [ 'kefu_id' => $supplier->kefu_id, 'name'=> $supplier->supplier_name, ]; } } //修改金额 建议零售价显示问题 $store_cloud = get_saas_purchase_store_cloud(); $store_id = $store_cloud->store_id; $rate = Store::find()->where(['id' => $store_id])->select('rate')->scalar() ?: 0; if (isset($goods['data']['list'])) { foreach ($goods['data']['list'] as &$goods_item) { $sale_price_type = Option::get('sale_price_type', $store_id, 'store')['value']; $goods_item['original_price'] = intval($sale_price_type) === 0 ? sprintf('%.2f', ($goods_item['platform_negotiated_price'] + ($goods_item['platform_negotiated_price']) * ($rate / 100))) : $goods_item['original_price']; $attrs = json_decode($goods_item['attrs'], true); foreach ($attrs as &$attr_item) { if (!intval($sale_price_type)) { $attr_item['original_price'] = sprintf('%.2f', ($attr_item['platform_negotiated_price'] + ($attr_item['platform_negotiated_price']) * ($rate / 100))); } } $goods_item['attrs'] = json_encode($attrs, JSON_UNESCAPED_UNICODE); } } return $this->asJson($goods); } /** * 商品列表 */ public function actionGoodsList() { $form = new MerchantForm(); $form->attributes = get_params(); $form->setSaasStoreCloudId(); if (!$form->token_stroe_cloud_id) { $this->asJson([ 'code' => 1, 'msg' => '未查到云仓用户' ]); } $store_cloud = get_saas_purchase_store_cloud(); if($store_cloud && $store_cloud->cloud_platform_list){ $cloud_platform_list = json_decode($store_cloud->cloud_platform_list, true); if($cloud_platform_list){ $form->supplier_id = implode(',', $cloud_platform_list); } } if (intval(get_params('type')) === 2) { $form->is_distribution = 0; } $form->store_id = $store_cloud->store_id; $this->asJson($form->mchGetGoodsList()); } //导入一个商品 public function actionMchGoodsImport(){ $post = post_params(); if(!is_array($post['id'])){ $post['id'] = [$post['id']]; } foreach($post['id'] as $id){ $_post = $post; $_post['id'] = $id; $form = new GoodsForm(); $form->attributes = $_post; $form->set_saas_purchase_store_id(); $goodsInfo = $form->saveCloudGoods(); if (isset($goodsInfo['code'])) { return $this->asJson($goodsInfo); } $merchantForm = new MerchantForm(); $merchantForm->setSaasStoreCloudId(); if (!$merchantForm->token_stroe_cloud_id) { return $this->asJson([ 'code' => 1, 'msg' => '未查到云仓用户' ]); } $bind = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'],$goodsInfo['goods_id']); } return $this->asJson($bind); } //导入商品列表 public function actionMchGoodsImports(){ $ids = post_params('ids'); $list = PurchaseImportCart::findAll(['id' => $ids, 'saas_id' => get_saas_user_id()]); foreach($list as $item){ $form = new GoodsForm(); $form->attributes = [ 'id' => $item['goods_id'], // 'store_id' => $item['store_id'], 'cat_id' => explode(',', $item['cat_ids']), ]; $form->set_saas_purchase_store_id(); $goodsInfo = $form->saveCloudGoods(); $merchantForm = new MerchantForm(); $merchantForm->setSaasStoreCloudId(); if (!$merchantForm->token_stroe_cloud_id) { $this->asJson([ 'code' => 1, 'msg' => '未查到云仓用户' ]); } $bind = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'],$goodsInfo['goods_id']); if($bind['code'] == 0){ PurchaseImportCart::deleteAll(['id' => $item['id']]); } } $this->asJson($bind); } //添加铺货单 public function actionAddMchGoodsImport(){ $res = [ 'code' => 1, 'msg' => '操作失败', ]; $post = post_params(); if (is_array($post['cat_id'])) { $post['cat_id'] = implode(',', $post['cat_id']); } $exist = PurchaseImportCart::findOne([ 'goods_id' => $post['id'], 'store_id' => get_saas_purchase_store_id(), 'cat_ids' => $post['cat_id'], 'saas_id' => get_saas_user_id(), ]); if($exist){ $res = [ 'code' => 0, 'msg' => '操作成功', ]; return $this->asJson($res); } $cart = new PurchaseImportCart(); $cart->goods_id = $post['id']; $cart->store_id = get_saas_purchase_store_id(); $cart->cat_ids = $post['cat_id']; $cart->saas_id = get_saas_user_id(); $save = $cart->save(); if($save){ $res = [ 'code' => 0, 'msg' => '操作成功', ]; } $this->asJson($res); } //修改铺货单 public function actionUpdateMchGoodsImport(){ $res = [ 'code' => 1, 'msg' => '操作失败', ]; $post = post_params(); $cart = PurchaseImportCart::findOne([ 'id' => $post['id'], ]); if(!$cart){ return $this->asJson($res); } $cart->cat_ids = implode(',', $post['cat_ids']); $cart->saas_id = get_saas_user_id(); $save = $cart->save(); if($save){ $res = [ 'code' => 0, 'msg' => '操作成功', ]; } $this->asJson($res); } //删除铺货单 public function actionDelMchGoodsImport(){ $res = [ 'code' => 1, 'msg' => '操作失败', ]; $ids = post_params('ids'); $del = PurchaseImportCart::deleteAll(['id' => $ids, 'saas_id' => get_saas_user_id()]); if($del){ $res = [ 'code' => 0, 'msg' => '操作成功', ]; } $this->asJson($res); } //获取铺货单 public function actionGetMchGoodsImport(){ $catList = Cat::find()->where([ 'store_id' => get_saas_purchase_store_id(), ])->all(); $list = PurchaseImportCart::findAll(['saas_id' => get_saas_user_id()]); foreach ($list as $i => $item) { $list[$i] = $item->toArray(); $list[$i]['cat_list'] = []; foreach (explode(',', $item['cat_ids']) as $citem) { foreach ($catList as $_citem) { if($citem == $_citem['id']){ $list[$i]['cat_list'][] = [ 'id' => $_citem['id'], 'name' => $_citem['name'], ]; } } } $form = new PlatformForm(); $form->id = $item['goods_id']; $glist = $form->goodsList(); if($glist['code'] == 0 && $glist['data']['count'] == 1){ $list[$i]['goods_info'] = $glist['data']['list'][0]; }else{ unset($list[$i]); } } $newList = array(); foreach ($list as $i => $item) { $supplier_id = $item['goods_info']['supplier_id']; $newList[$supplier_id]['supplier'] = $item['goods_info']['supplier']; $newList[$supplier_id]['goods_list'][] = $item; } $res = [ 'code' => 0, 'msg' => '操作成功', 'data' => array_values($newList), ]; $this->asJson($res); } /** * 添加商品或店铺到我的喜欢 */ public function actionFavoriteAdd() { $form = new FavoriteForm(); $form->attributes = post_params(); $form->store_id = get_saas_purchase_store_id(); $form->saas_id = get_saas_user_id(); return $this->asJson($form->add()); } /** * 喜欢的商品或店铺列表 */ public function actionFavoriteList() { $form = new FavoriteForm(); $form->attributes = get_params(); $form->store_id = get_saas_purchase_store_id(); $form->saas_id = get_saas_user_id(); return $this->asJson($form->search()); } /** * 取消喜欢的商品或店铺列表 */ public function actionFavoriteRemove() { $form = new FavoriteForm(); $form->attributes = post_params(); $form->store_id = get_saas_purchase_store_id(); $form->saas_id = get_saas_user_id(); return $this->asJson($form->remove()); } /** * 申请供货商 */ public function actionApplySupplier() { $tel = post_params('tel'); $form = new PlatformForm(); $form->attributes = post_params(); if ($tel) { $admin = Admin::findOne(['mobile' => $tel, 'is_delete' => 0, 'type' => 'supplier']); if ($admin) { // if ($admin->type !== 'supplier') { // return $this->asJson([ // 'code' => 1, // 'msg' => '当前手机号已经绑定' // ]); // } $supplier = Supplier::findOne($admin->type_id); if ($supplier) { if ((int)$supplier->status === 1) { return $this->asJson([ 'code' => 1, 'msg' => '当前已经为供货商' ]); } elseif ((int)$supplier->status === 2) { $form->id = $supplier->cloud_supplier_id; $form->status = 0; return $this->asJson($form->editSupplier()); } else { return $this->asJson([ 'code' => 1, 'msg' => '供货商信息审核中不可编辑' ]); } } } } $form->saas_user_id = get_saas_user_id(); return $this->asJson($form->createSupplier()); } /** * 获取供货商信息 */ public function actionGetSupplierApply() { $saas_user = get_saas_user(); if ($saas_user->id) { $suppler = Supplier::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]); if (!empty($suppler->cloud_supplier_id)) { $form = new PlatformForm(); $form->ids = $suppler->cloud_supplier_id; $res = $form->listSupplier(); $res['data'] = $res['data']['list'][0]; $res['data']['url'] = \Yii::$app->request->hostInfo . '/admin/#/login'; $res['data']['password'] = $suppler->password; } else { $res = [ 'code' => 0, 'data' => [ "supplier_name" => "", "name" => "", "logo" => "", "tel" => $saas_user->mobile, "type" => "", "certificate" => "", "id_card_reverse" => "", "id_card_front" => "", "sale_day" => "", "status" => "", "url" => \Yii::$app->request->hostInfo . '/admin/#/login' ], 'msg' => '获取成功' ]; } return $this->asJson($res); } else { return $this->asJson([ 'code' => 1, 'data' => '未获取登陆状态' ]); } } /** * 创建转单 */ public function actionCreateOrderTrans() { $order_id = post_params('order_id'); $order = Order::findOne($order_id); $order_detail = OrderDetail::find()->where(['order_id' => $order_id])->select('goods_id')->asArray()->all(); if (!empty($order) && !empty($order_detail)) { $form = new MerchantForm(); $form->address = $order->address; $form->province_id = $order->province_id; $form->city_id = $order->city_id; $form->district_id = $order->district_id; $form->order_id = $order_id; $form->tel = $order->mobile; $form->name = $order->name; $form->store_id = $order->store_id; $result = $form->mchSetPurchaseOrder(); return $this->asJson($result); } else { return $this->asJson([ 'code' => 1, 'msg' => '订单信息错误' ]); } } /** * 设置云仓 */ public function actionStoreRate() { try { $saas_user_id = get_saas_user_id(); $store_cloud = StoreCloud::find() ->where(['AND', ['saas_user_id' => $saas_user_id, 'is_delete' => 0], ['>', 'store_id', 0]])->asArray()->one(); if (!$store_cloud) { throw new \Exception('当前云仓账户未绑定商城信息'); } $store_id = $store_cloud['store_id']; $store = Store::findOne(['id' => $store_id, 'is_delete' => 0]); if (!$store) { throw new \Exception('商城信息查找失败'); } $data = []; if (\Yii::$app->request->isGet) { $cloud_is_update = Option::get('cloud_is_update', $store_id, 'store')['value']; $reduce_type = Option::get('reduce_type', $store_id, 'store')['value']; $sale_price_type = Option::get('sale_price_type', $store_id, 'store')['value']; $arr = [ 'rate' => $store->rate, // 'is_auth_trans' => $store->is_auth_trans, 'cloud_is_update' => (int)$cloud_is_update, 'reduce_type' => $reduce_type, 'sale_price_type' => (int)$sale_price_type ]; //自动优先扣除方式 $form = new MerchantForm(); $result = $form->setCloudMerchantConfig(null, $store_cloud['id']); if ($result['code'] === 0) { $arr['reduce_type'] = (int)$result['data']['reduce_type']; } $data = [ 'code' => 0, 'msg' => "获取成功", 'data' => $arr ]; } elseif (\Yii::$app->request->isPost) { $rate = floatval(post_params('rate', 0)); $reduce_type = post_params('reduce_type', 0); // $is_auth_trans = post_params('is_auth_trans', 0); $cloud_is_update = post_params('cloud_is_update', 0); $sale_price_type = post_params('sale_price_type', 0); Option::set('sale_price_type', $sale_price_type, $store_id, 'store'); Option::set('cloud_is_update', $cloud_is_update, $store_id, 'store'); Option::set('reduce_type', $reduce_type, $store_id, 'store'); $store->rate = $rate; // $store->is_auth_trans = $is_auth_trans; if (!$store->save()) { throw new \Exception(json_encode($store->errors)); } //自动优先扣除方式 $form = new MerchantForm(); $result = $form->setCloudMerchantConfig($reduce_type, $store_cloud['id']); $data = [ 'code' => 0, 'msg' => "操作成功", ]; } return $this->asJson($data); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), ]); } } }