| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace addons\CloudStock\api\modules\v1\controllers;
- use addons\CloudStock\common\models\CloudStockAgent;
- use addons\CloudStock\common\models\CloudStockAgentGoods;
- use addons\CloudStock\common\models\CloudStockGoods;
- use addons\CloudStock\common\services\LossAmountService;
- use addons\CloudStock\common\services\PriceDifferenceProfitService;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\models\user\User;
- class IndexController extends BaseController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (!\Yii::$app->request->isGet) {
- return $this->error('请求方式错误');
- }
- $mall_id = $this->mall_id;
- $user_id = $this->user_id;
- $cloudStockGoodsList = CloudStockGoods::lists(['where'=>[['mall_id'=>$this->mall_id],['status'=>StatusEnum::ENABLED]]]);
- $goods_ids = array_column($cloudStockGoodsList,'goods_id');
- $data['agent_stock_goods_amount'] = CloudStockAgentGoods::find()
- ->where(['mall_id' => $mall_id, 'user_id' => $user_id,'goods_id'=>$goods_ids, 'status' => StatusEnum::ENABLED])
- ->sum('num');
- $stock_agent = $this->stock_agent;
- if (!empty($stock_agent->user)) {
- $user = $stock_agent->user;
- } else {
- $user = User::findOne(["id" => $user_id, "mall_id" => $mall_id, 'status' => StatusEnum::ENABLED]);
- }
- $data['agent_price'] = $stock_agent->price;
- $data['agent_frozen_price'] = $stock_agent->frozen_price;
- $data['agent_level'] = $stock_agent->level;
- $data['agent_level_name'] = $stock_agent->stockLevel->name;
- $data['agent_nickname'] = $user->nickname ?: '默认会员';
- $data['agent_user_id'] = $user->id;
- $data['agent_avatar_url'] = $user->avatar_url;
- $parent_user = $user->parent;
- if ($parent_user) {
- $data['parent_user_nickname'] = $parent_user->nickname;
- } else {
- $data['parent_user_nickname'] = "平台";
- }
- $data['parent_user_id'] = $parent_user->id ?? 0;
- $data['is_give_quota'] = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_CLOUD_STOCK, 'basic.is_give_quota');
- $pay_config = json_decode(\Yii::$app->services->setting->mall->get($this->mall_id, 'pay.balance'), true);
- $data['pay_password_status'] = $pay_config['pay_password_status'];
- $data['cloud_warehouse_frozen_price'] = $stock_agent->cloud_warehouse_frozen_price;
- $data['cloud_warehouse_price'] = $stock_agent->cloud_warehouse_price;
- $data['cloud_warehouse_withdraw_price'] = $stock_agent->cloud_warehouse_withdraw_price;
- $configs = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_CLOUD_STOCK, 'basic');
- if(isset($configs['cloud_stock_index'])){
- $data['cloud_stock_index'] = json_decode($configs['cloud_stock_index'],true);
- }else{
- $data['cloud_stock_index'] = json_decode('[{"name":"云仓库存","title":"云仓库存","code":"agent_stock_goods_amount","is_show":"1"},{"name":"待结算货款","title":"待结算货款","code":"agent_frozen_price","is_show":"1"},{"name":"已结算收益","title":"已结算收益","code":"agent_price","is_show":"1"},{"name":"云仓待结货款","title":"云仓待结货款","code":"cloud_warehouse_frozen_price","is_show":"1"},{"name":"待结算货款","title":"云仓已结货款","code":"cloud_warehouse_price","is_show":"1"}]', true);
- }
- if(isset($configs['my_cloud_stock'])){
- $data['my_cloud_stock'] = json_decode($configs['my_cloud_stock'],true);
- }else{
- $data['my_cloud_stock'] = json_decode('[{"name":"库存明细","title":"库存明细","code":"inventory_details","is_show":"1"},{"name":"补货","title":"补货","code":"replenish","is_show":"1"},{"name":"云仓配货","title":"云仓配货","code":"distribution","is_show":"1"},{"name":"提货到线下","title":"提货到线下","code":"pick_up_goods","is_show":"1"}]', true);
- }
- $data['is_show_cloud_stock_partition'] = $configs['is_show_cloud_stock_partition']??0;
- $is_show_agreement_content = $configs['is_show_agreement_content'] ?? 0;
- $agreement_content = '';
- if (!empty($is_show_agreement_content)) {
- $agreement_content = $configs['agreement_content'] ?? '';
- }
- $data['agreement_content'] = $agreement_content;
- $data['equal_award_frozen_price'] = $stock_agent['equal_award_frozen_price'];
- $data['equal_award_price'] = $stock_agent['equal_award_price'];
- $data['total_equal_award_price'] = bcadd($stock_agent['equal_award_price'], $stock_agent['equal_award_frozen_price'], 2);
- $data['loss_amount'] = $stock_agent['loss_amount'];
- $data['difference_profit'] = $stock_agent['difference_profit'];
- $data['agent_stock_goods_amount'] = $data['agent_stock_goods_amount'] ?? 0;
- $data['is_show_setting'] = $configs['is_show_setting'] ?? 0;
- $data['is_show_stock_permission'] = $data['is_show_setting'] ? $configs['is_show_stock_permission'] ?? 0 : 0;
- $data['is_stock_deducted_by_subordinate'] = $this->stock_agent->is_stock_deducted_by_subordinate ?? 0;
- $data['is_enable_rand_fee'] = $configs['is_enable_rand_fee'] ?? 0;
- $data['condition'] = json_decode($configs['rand_condition'],true);
- return $this->success("成功", $data);
- }
- public function actionLossAmountList()
- {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $list = (new LossAmountService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->lossAmountList($params);
- return $this->success('操作成功', $list);
- }
- public function actionPriceDifferenceProfitList()
- {
- $params = \Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $list = (new PriceDifferenceProfitService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->priceDifferenceProfitList($params);
- return $this->success('操作成功', $list);
- }
- }
|