HappinessStore.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use addons\Happiness\common\models\HappinessStoreAdmin;
  4. use addons\Happiness\common\enums\HappinessEnum;
  5. use addons\Store\common\models\StoreAssociatedUser;
  6. use addons\Store\common\models\StoreCommission;
  7. use addons\Store\common\models\StoreMerchantReduceProfit;
  8. use addons\Store\common\models\StoreOrder;
  9. use addons\Store\common\models\StoreOrderDetail;
  10. use addons\Store\common\models\StoreSettings;
  11. use addons\Store\common\models\StoreStatistics;
  12. use common\enums\AddonsEnum;
  13. use common\enums\OrderStatusEnum;
  14. use common\enums\PayTypeEnum;
  15. use common\enums\StatusEnum;
  16. use common\enums\UserWalletEnum;
  17. use common\models\base\BaseActiveRecord;
  18. use common\models\common\CapitalLog;
  19. use common\models\mall\Mall;
  20. use common\models\mall\MallAddons;
  21. use common\models\order\Order;
  22. use common\models\user\User;
  23. use services\common\UserWalletService;
  24. use Yii;
  25. use yii\console\ExitCode;
  26. use yii\db\Exception;
  27. /**
  28. * This is the model class for table "qimall_addons_happiness_store".
  29. *
  30. * @property int $id
  31. * @property int $mall_id
  32. * @property int $user_id 绑定会员id
  33. * @property string $shop_owner 店长姓名
  34. * @property string $shop_mobile 店长手机号
  35. * @property string $store_name 门店名称
  36. * @property string $store_desc 门店简介
  37. * @property string $logo_img 门店logo
  38. * @property string $store_img 门店图片
  39. * @property string $license_img 营业执照
  40. * @property int|null $province_id 省
  41. * @property int|null $city_id 市
  42. * @property int|null $district_id 区
  43. * @property string $address 详细地址
  44. * @property int $expire_time 失效时间,0代表无限期
  45. * @property float $total_money 累计收入
  46. * @property float $share_amount 累计收入
  47. * @property float $balance 当前余额
  48. * @property float $frozen_balance 冻结余额
  49. * @property float $total_expenses 累计支出
  50. * @property int|null $user_nums 会员总数
  51. * @property string $longitude 经度
  52. * @property string $latitude 维度
  53. * @property int $check_status 审核状态:0:待审核;1:已通过;2:未通过
  54. * @property string $check_remark 审核备注
  55. * @property string $business_time_start 营业时间开始
  56. * @property string $business_time_end 营业时间结束
  57. * @property string $freight_type 配送设置
  58. * @property string $intra_city_distribution 同城配送
  59. * @property float $total_order_money 订单总金额
  60. * @property int $refund_money 退款金额
  61. * @property float $refund_num 退款订单数量
  62. * @property float $fine_money 罚款金额
  63. * @property int $total_num 总数
  64. * @property float $total_settled_amount 已结算总金额
  65. * @property float $unsettled_amount 未结算金额
  66. * @property int $sales_volume 销量
  67. * @property int $no 编号
  68. * @property int $merchant_distribution 商家配送
  69. * @property float $praise 评分
  70. * @property int $status 状态[0禁用 1启用 -1删除]
  71. * @property int $shop_status 门店营业状态,1:正在营业;0:休息中
  72. * @property int $created_at 创建时间
  73. * @property int $updated_at 修改时间
  74. * @property int $business_id 业务员ID
  75. * @property string $huifu_no 汇付号
  76. */
  77. class HappinessStore extends BaseActiveRecord
  78. {
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public static function tableName()
  83. {
  84. return '{{%addons_happiness_store}}';
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function rules()
  90. {
  91. return [
  92. [['mall_id', 'user_id', 'province_id', 'city_id', 'district_id','street_id','expire_time', 'user_nums',
  93. 'total_num', 'sales_volume', 'status', 'shop_status', 'created_at', 'updated_at', 'merchant_distribution', 'self_mention', 'is_alone','business_id','check_status'], 'integer'],
  94. [['total_money', 'balance','frozen_balance','refund_money','refund_num', 'fine_money', 'total_expenses', 'total_order_money', 'total_settled_amount', 'unsettled_amount', 'praise', 'share_amount', 'distribution_scope'], 'number'],
  95. [['shop_owner', 'store_name', 'store_desc', 'logo_img', 'license_img', 'address', 'longitude', 'latitude',
  96. 'business_time_start', 'business_time_end','check_remark'], 'string', 'max' => 255],
  97. [['huifu_no'], 'string', 'max' => 100],
  98. [['intra_city_distribution','no'], 'string', 'max' => 500],
  99. [['shop_mobile'], 'string', 'max' => 11],
  100. ];
  101. }
  102. /**
  103. * {@inheritdoc}
  104. */
  105. public function attributeLabels()
  106. {
  107. return [
  108. 'id' => 'ID',
  109. 'mall_id' => 'Mall ID',
  110. 'user_id' => '绑定会员id',
  111. 'no' => '编号',
  112. 'business_id'=>'业务员ID',
  113. 'shop_owner' => '店长姓名',
  114. 'shop_mobile' => '店长手机号',
  115. 'store_name' => '门店名称',
  116. 'store_desc' => '门店简介',
  117. 'logo_img' => '门店logo',
  118. 'license_img' => '营业执照',
  119. 'province_id' => '省',
  120. 'city_id' => '市',
  121. 'district_id' => '区',
  122. 'street_id' => '街道',
  123. 'community_id' => '社区',
  124. 'address' => '详细地址',
  125. 'expire_time' => '失效时间,0代表无限期',
  126. 'total_money' => '累计收入',
  127. 'balance' => '当前余额',
  128. 'frozen_balance' => '冻结余额',
  129. 'total_expenses' => '累计支出',
  130. 'user_nums' => '会员总数',
  131. 'longitude' => '经度',
  132. 'latitude' => '维度',
  133. 'check_status' => '审核状态:0:待审核;1:已通过;2:未通过',
  134. 'check_remark' => '审核备注',
  135. 'business_time_start' => '营业时间开始',
  136. 'business_time_end' => '营业时间结束',
  137. 'freight_type' => '配送设置',
  138. 'intra_city_distribution' => '同城配送',
  139. 'total_order_money' => '订单总金额',
  140. 'total_num' => '总数',
  141. 'total_settled_amount' => '已结算总金额',
  142. 'unsettled_amount' => '未结算金额',
  143. 'refund_money' => '退款金额',
  144. 'refund_num'=>'退款订单数量',
  145. 'file_money' => '罚款金额',
  146. 'status' => '状态[0禁用 1启用 -1删除]',
  147. 'shop_status' => '门店营业状态',
  148. 'created_at' => '创建时间',
  149. 'updated_at' => '修改时间',
  150. ];
  151. }
  152. public static function setData(array $params, bool $is_custom_pwd = false)
  153. {
  154. $t = Yii::$app->db->beginTransaction();
  155. try {
  156. if (!empty($params['id'])) {
  157. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  158. if (empty($model)) throw new \Exception('门店不存在或已删除');
  159. } else {
  160. $model = new self();
  161. $model->loadDefaultValues();
  162. // $model->expire_time = strtotime("+1 year");
  163. }
  164. // if (!empty($params['freight_type'])) $params['freight_type'] = json_encode($params['freight_type']);
  165. if (!empty($params['intra_city_distribution'])) $params['intra_city_distribution'] = json_encode($params['intra_city_distribution']);
  166. if (!$model->load($params, '') || !$model->save()) {
  167. throw new \Exception($model->getErrorMessage());
  168. }
  169. $store_addmin = HappinessStoreAdmin::findOne(['mall_id' => $params['mall_id'], 'store_id' => $model->id, 'status' => StatusEnum::ENABLED]);
  170. // 同步一下账号
  171. if ($store_addmin) {
  172. if ($model->shop_mobile != $store_addmin->username) {
  173. $pwd_str = substr($model->shop_mobile, -6);
  174. if ($is_custom_pwd) $pwd_str = $params['password'];
  175. $pwd_hash_str = \Yii::$app->security->generatePasswordHash($pwd_str);
  176. $store_addmin->username = $model->shop_mobile;
  177. $store_addmin->password = $pwd_hash_str;
  178. if (!$store_addmin->save()) throw new \Exception($store_addmin->getErrorMessage());
  179. }
  180. }
  181. $t->commit();
  182. return $model;
  183. } catch (\Exception $e) {
  184. $t->rollBack();
  185. self::$static_error = $e->getMessage() . $e->getLine() . $e->getFile();
  186. return false;
  187. }
  188. }
  189. /**
  190. * @param array $params
  191. * @param \Closure|null $callback
  192. * @param bool $is_custom_pwd //是否自定义密码
  193. * @return bool {*}
  194. * @throws Exception
  195. * @throws \yii\base\Exception
  196. * @msg: 添加一个门店,同时添加门店后台的管理员。默认账号是门店绑定手机号,默认登录密码是手机号后六位
  197. */
  198. public static function addStore(array $params, \Closure $callback = null, bool $is_custom_pwd = false)
  199. {
  200. //查询业务员
  201. $business = User::find()
  202. ->andWhere(['mall_id' => $params['mall_id']])
  203. ->andWhere([
  204. 'or',
  205. ['id' => $params['business_id']],
  206. ['mobile' => $params['business_id']]
  207. ])
  208. ->one();
  209. if(empty($business))
  210. {
  211. self::$static_error = '推广员不存在';
  212. return false;
  213. }
  214. $business=HappinessBusiness::find()->where(['mall_id' => $params['mall_id'], 'user_id' => $business->id])
  215. ->one();
  216. if(empty($business))
  217. {
  218. self::$static_error = '用户'.$business->id.'不是推广员';
  219. return false;
  220. }
  221. $params['business_id'] = $business->user_id;
  222. $transaction = \Yii::$app->db->beginTransaction();
  223. $res = self::setData($params, $is_custom_pwd);
  224. if (false === $res) {
  225. $transaction->rollBack();
  226. return false;
  227. }
  228. $pwd_str = substr($params['shop_mobile'], -6);
  229. if ($is_custom_pwd) $pwd_str = $params['password'];
  230. $pwd_hash_str = \Yii::$app->security->generatePasswordHash($pwd_str);
  231. $admin_info = [
  232. 'username' => $params['shop_mobile'],
  233. 'account' => $params['shop_owner'],
  234. 'password' => $pwd_hash_str,
  235. 'mall_id' => $params['mall_id'],
  236. 'admin_type' => 2,
  237. 'status' => StatusEnum::ENABLED,
  238. 'user_id' => $params['user_id'],
  239. 'store_id' => $res->id,
  240. ];
  241. $admin_model = HappinessStoreAdmin::find()
  242. ->where(['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED, 'username' => $params['shop_mobile']])
  243. ->one();
  244. if (!empty($admin_model) && $admin_model['store_id'] != $res->id) {
  245. $transaction->rollBack();
  246. self::$static_error = '门店管理员账号已经存在';
  247. return false;
  248. }
  249. $admin_model = new HappinessStoreAdmin();
  250. $admin_model->loadDefaultValues();
  251. $admin_model->attributes = $admin_info;
  252. $admin_model->updated_at = time();
  253. $admin_model->created_at = time();
  254. $res_ad = $admin_model->save();
  255. if (false === $res_ad) {
  256. $transaction->rollBack();
  257. self::$static_error = $admin_model->getErrorMessage();
  258. return false;
  259. }
  260. $transaction->commit();
  261. return $res;
  262. }
  263. public static function saveStoreSetting(int $mall_id, array $data, array $addons_settings = [])
  264. {
  265. $transaction = \Yii::$app->db->beginTransaction();
  266. $store_info = [
  267. 'shop_status' => $data['shop_status'],
  268. 'shop_mobile' => $data['username'],
  269. 'business_time_start' => $data['business_time_start'],
  270. 'business_time_end' => $data['business_time_end'],
  271. 'id' => $data['store_id'],
  272. 'mall_id' => $mall_id,
  273. 'intra_city_distribution' => $data['intra_city_distribution'] ?? [],
  274. 'merchant_distribution' => $data['merchant_distribution'],
  275. 'self_mention' => $data['self_mention'],
  276. 'is_alone' => $data['is_alone'],
  277. 'distribution_scope' => $data['distribution_scope'],
  278. ];
  279. $store_res = self::setData($store_info);
  280. if (false === $store_res) {
  281. $transaction->rollBack();
  282. self::$static_error = self::getStaticError();
  283. return false;
  284. }
  285. //判断门店是否存在
  286. $admin_model = HappinessStoreAdmin::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'username' => $store_res->shop_mobile]);
  287. if (empty($admin_model)) {
  288. $transaction->rollBack();
  289. self::$static_error = '门店管理员账号不存在';
  290. return false;
  291. }
  292. // 因为上一步已经有账号变更现在只要密码变更就行
  293. if (!empty($data['password'])) {
  294. $admin_model->password = \Yii::$app->security->generatePasswordHash($data['password']);
  295. $admin_model->updated_at = time();
  296. $admin_res = $admin_model->save();
  297. if (empty($admin_res)) {
  298. $transaction->rollBack();
  299. self::$static_error = $admin_model->getErrorMessage();
  300. return false;
  301. }
  302. }
  303. $transaction->commit();
  304. return true;
  305. }
  306. /**
  307. * @name:
  308. * @msg: 装修页面获取门店列表
  309. * @param {int} $mall_id
  310. * @param {array} $params
  311. * @return {*}
  312. */
  313. public static function getStoreListInDiy(int $mall_id, array $params = [])
  314. {
  315. $wheres[] = ['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED];
  316. if (!empty($params['store_id'])) {
  317. $wheres[] = ['id' => $params['store_id']];
  318. }
  319. if (!empty($params['store_name'])) {
  320. $wheres[] = ['like', 'store_name', $params['store_name']];
  321. }
  322. if (!empty($params['storeowner'])) {
  323. $wheres[] = ['like', 'shop_owner', $params['storeowner']];
  324. }
  325. $params = [
  326. 'select' => '*,store_name as title,logo_img as img',
  327. 'where' => $wheres,
  328. 'order' => 'created_at desc',
  329. ];
  330. $store_list = self::listPage($params);
  331. if (false === $store_list) {
  332. return false;
  333. }
  334. return $store_list;
  335. }
  336. //获取门店更多
  337. public static function MoreStore(string $storeList, int $mall_id)
  338. {
  339. $params = [
  340. 'select' => '*,store_name as title,logo_img as img',
  341. 'where' => "id in ($storeList) and status = 1 and check_status = 1 and mall_id = $mall_id and shop_status = 1",
  342. 'order' => 'created_at desc',
  343. ];
  344. $store_list = self::listpage($params);
  345. if (false === $store_list) {
  346. return false;
  347. }
  348. $decoration = \Yii::$app->services->setting->addons->get($mall_id, HappinessEnum::ADDONS_NAME, 'decoration');
  349. foreach ($store_list['list'] as &$item) {
  350. if (!empty($decoration['custom_store_style'])) {
  351. $item['store_style'] = $item['show_style'] ?? 1;
  352. } else {
  353. $item['store_style'] = $decoration['default_store_style'] ?? 1;
  354. }
  355. }
  356. return $store_list;
  357. }
  358. /**
  359. * 结算货款
  360. *
  361. * @param int $order_id
  362. * @param int $store_id
  363. * @param string $order_no
  364. * @param integer $is_settlement 是否已经结算订(用于虚拟订单直接结算, 虚拟订单生成的佣金记录是已结算的,所以需要传1查询)
  365. * @return void
  366. */
  367. public static function settlementStoreCommission($order_id, $store_id, $order_no, $is_settlement = 0)
  368. {
  369. $store = \addons\Store\common\models\Store::findOne(['id' => $store_id]);
  370. $store_commission_model = StoreCommission::findOne(['order_no' => $order_no, 'is_settlement' => $is_settlement, 'status' => StatusEnum::ENABLED]);
  371. if ($store_commission_model) {
  372. // 配置信息
  373. $storeSetting = StoreSettings::findOne(['store_id' => $store->id]);
  374. $order = StoreOrder::findOne(['id' => $order_id]);
  375. if ($storeSetting->store_service_fee == 2 && MallAddons::isInstall($store->mall_id, AddonsEnum::ADDONS_NAME_HUIFU_PAY) && $order->payment_type == PayTypeEnum::HUIFUPAY) {
  376. $store->share_amount += $store_commission_model->amount_received; // 已分帐金额
  377. } else {
  378. $store->balance += $store_commission_model->amount_received; // 余额
  379. $store->total_settled_amount += $store_commission_model->amount_received; // 已结算总金额
  380. }
  381. $store->unsettled_amount -= $store_commission_model->amount_received; // 未结算
  382. if ($store->unsettled_amount < 0) $store->unsettled_amount = 0;
  383. $res = $store->save();
  384. if ($res == false) throw new Exception('o2o订单完成结算货款,更新店铺结算金额失败,order_no:' . $order_no);
  385. $store_commission_model->is_settlement = 1;
  386. $res = $store_commission_model->save();
  387. if ($res == false) throw new Exception('o2o订单完成结算货款,更新提成记录失败,order_no:' . $order_no);
  388. StoreStatistics::updateIncomeMoney($store, $store_commission_model->amount_received);
  389. $key = HappinessEnum::STORE_NOT_SETTLE_AMOUNTS . ':' . $store['mall_id'];
  390. $res = Yii::$app->redis->get($key);
  391. $amount_received_temp = $store_commission_model->amount_received;
  392. if (!empty($res)) $amount_received_temp = bcsub($res, $store_commission_model->amount_received, 2);
  393. if ($amount_received_temp < 0) $amount_received_temp = 0;
  394. Yii::$app->redis->set($key, $amount_received_temp);//待结算
  395. $amount_received_temp = $store_commission_model->amount_received;
  396. $key = HappinessEnum::STORE_SETTLE_AMOUNTS . ':' . $store['mall_id'];
  397. $res = \Yii::$app->redis->get($key);
  398. if (!empty($res)) $amount_received_temp = bcadd($res, $store_commission_model->amount_received, 2);
  399. Yii::$app->redis->set($key, $amount_received_temp);//已结算
  400. //结算积分
  401. if (!empty($store_commission_model['score_deduction_bear']) && $store_commission_model['score_deduction_bear'] == 1) {
  402. self::settlementScore($order_no, $store['user_id'], $store_commission_model['id']);
  403. }
  404. }
  405. }
  406. /**
  407. * 结算积分
  408. * @param $order_no
  409. * @param $store_user_id
  410. * @param $source_table_id
  411. * @return void
  412. */
  413. public static function settlementScore($order_no, $store_user_id, $source_table_id)
  414. {
  415. $store_order = StoreOrder::findOne(['order_no' => $order_no]);
  416. $store_order_detail_list = StoreOrderDetail::find()->where(['order_id' => $store_order['id'], 'is_feedback' => 0])->all();
  417. $order_detail_ids = array_column($store_order_detail_list, 'id');
  418. $source_table = StoreOrderDetail::tableName();
  419. CapitalLog::$capitalType = 'score';
  420. $score_frozen_log_list = CapitalLog::lists(
  421. [
  422. 'where' => [
  423. ['user_id' => $store_order['user_id']],
  424. ['change_type' => 'sub'],
  425. ['source_table' => $source_table],
  426. ['source_table_id' => $order_detail_ids],
  427. ['from_type' => UserWalletEnum::CONSUME],
  428. ['capital_type' => 'consume_store_order'],
  429. ]
  430. ]
  431. );
  432. if (!empty($score_frozen_log_list)) {
  433. $received_score = array_sum(array_column($score_frozen_log_list, 'change_num'));
  434. if ($received_score > 0) {
  435. $desc = '门店订单:' . $order_no . ':积分结算' . $received_score;
  436. $data = [
  437. 'message_id' => 0,
  438. 'mall_id' => $store_order['mall_id'],
  439. 'user_id' => $store_user_id,
  440. 'wallet_type' => 'score',
  441. 'is_frozen' => false,
  442. 'unfrozen' => false,
  443. 'money' => $received_score,
  444. 'desc' => $desc,
  445. 'source_table' => StoreCommission::tableName(),
  446. 'source_table_id' => $source_table_id,
  447. 'from_type' => AddonsEnum::ADDONS_NAME_STORE,
  448. 'capital_type' => 'consume_store_order',
  449. 'order_no' => $order_no
  450. ];
  451. UserWalletService::handle(0, $data);
  452. }
  453. }
  454. }
  455. /**
  456. * 通过ID获取手机号码
  457. *
  458. * @param integer $id
  459. * @return string|null
  460. */
  461. public static function getMobileById(int $mall_id, int $id)
  462. {
  463. return static::find()
  464. ->where(['mall_id' => $mall_id, 'id' => $id])
  465. ->select('shop_mobile')
  466. ->scalar();
  467. }
  468. public static function delStore($mall_id, $store_id)
  469. {
  470. $store = self::findOne(['id' => $store_id, 'mall_id' => $mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  471. if (empty($store)) throw new \Exception('门店不存在');
  472. if ($store['balance'] > 0) throw new \Exception('店铺余额不为0,请先提现后再删除');
  473. $where = [
  474. ['yo.mall_id' => $mall_id],
  475. ['yo.store_id' => $store_id],
  476. ['o.order_status' => [OrderStatusEnum::PAY, OrderStatusEnum::SHIPMENTS, OrderStatusEnum::SING, OrderStatusEnum::TAKE]],
  477. ];
  478. $alias = 'yo';
  479. $order = "id desc";
  480. $join = [['LEFT JOIN', Order::tableName(). ' as o', "o.id = yo.order_id"]];
  481. $select = 'o.*,yo.store_id';
  482. $params = compact('where', 'order', 'alias', 'join', 'select');
  483. $store_order = HappinessOrder::lists($params);
  484. if (!empty($store_order)) throw new \Exception('请等订单完成后再删除');
  485. $t = Yii::$app->db->beginTransaction();
  486. try {
  487. $store->status = StatusEnum::DELETE;
  488. $res = $store->save();
  489. if (empty($res)) throw new \Exception('删除失败');
  490. HappinessStoreAdmin::updateAll(['status' => StatusEnum::DELETE], ['store_id' => $store_id, 'mall_id' => $mall_id]);
  491. //删除门店关联的核销员
  492. HappinessClerk::updateAll(['Status' => StatusEnum::DELETE], ['mall_id' => $mall_id, 'store_id' => $store_id]);
  493. // StoreAssociatedUser::updateAll(['status' => StatusEnum::DELETE], ['store_id' => $store_id, 'mall_id' => $mall_id]);
  494. $t->commit();
  495. } catch (\Exception $e) {
  496. $t->rollBack();
  497. throw new \Exception($e->getMessage());
  498. }
  499. return true;
  500. }
  501. public static function fixData()
  502. {
  503. $mall_list = Mall::getEnableMallList(true);
  504. $mall_ids = array_column($mall_list, 'id');
  505. if (empty($mall_ids)) {
  506. echo '没有可用商城,不做处理 ... ' . PHP_EOL;
  507. return ExitCode::UNSPECIFIED_ERROR;
  508. }
  509. foreach ($mall_ids as $mall_id) {
  510. $key = HappinessEnum::STORE_NOT_SETTLE_AMOUNTS . ':' . $mall_id;
  511. $not_settle_amounts = StoreCommission::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'is_settlement' => 0])->sum('amount_received');
  512. if (empty($not_settle_amounts)) $not_settle_amounts = 0;
  513. \Yii::$app->redis->set($key, $not_settle_amounts);
  514. $key = HappinessEnum::STORE_SETTLE_AMOUNTS . ':' . $mall_id;
  515. $settle_amounts = StoreCommission::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'is_settlement' => 1])->sum('amount_received');
  516. if (empty($settle_amounts)) $settle_amounts = 0;
  517. \Yii::$app->redis->set($key, $settle_amounts);
  518. var_dump($mall_id);
  519. }
  520. }
  521. /**
  522. * 门店自提码设置
  523. *
  524. * @param integer $store_id
  525. * @return array
  526. */
  527. public static function getStorePickup(int $store_id)
  528. {
  529. $pickup = static::find()
  530. ->where(['id' => $store_id])
  531. ->select('pickup')
  532. ->scalar();
  533. return empty($pickup) ? [] : json_decode($pickup, true);
  534. }
  535. public function getBusiness(){
  536. return $this->hasOne(User::class, ['id' => 'business_id']);
  537. }
  538. }