| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace console\controllers;
- use biz\shop\classes\ShopClass;
- use bizGhs\cg\classes\CgOrderClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use common\components\noticeUtil;
- use yii\console\Controller;
- use Yii;
- class BookController extends Controller
- {
- //全部待入库采购单重新分配货位 ssh 20240711
- public function actionAssignSeat()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $cacheKey = 'assign_seat_main_book_sn_list';
- $num = Yii::$app->redis->executeCommand('SCARD', [$cacheKey]);
- if ($num <= 0) {
- echo "没有数量\n";
- return false;
- }
- if ($num > 15) {
- noticeUtil::push("assign seat all 已经超过15家了,请及时解决", '15280215347');
- }
- $list = Yii::$app->redis->executeCommand('SMEMBERS', [$cacheKey]);
- if (empty($list)) {
- echo "没有数量哦\n";
- return false;
- }
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- Yii::$app->params['errorReport'] = 1;
- foreach ($list as $key => $bookSn) {
- $cgList = CgOrderClass::getAllByCondition(['bookSn' => $bookSn, 'status' => 3], null, '*', null, true);
- if (empty($cgList)) {
- //noticeUtil::push("bookSn:{$bookSn} 没有采购单需要分配货位", '15280215347');
- continue;
- }
- foreach ($cgList as $cg) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $cg->shopId??0;
- $shop = ShopClass::getById($shopId,true);
- if(empty($shop)){
- continue;
- }
- $staffId = $cg->shopAdminId??0;
- $staffName = $cg->shopAdminName??'';
- $params = ['staffId'=>$staffId,'staffName'=>$staffName];
- $respond = PurchaseOrderClass::assign($cg,$shop,$params);
- $transaction->commit();
- $hasChange = $respond['hasChange'] ?? 0;
- if ($hasChange == 1) {
- //通知采购单页要刷新货位
- $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
- $mainId = $cg->mainId ?? 0;
- $cgId = $cg->id ?? 0;
- $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (!empty($staffList)) {
- foreach ($staffList as $staff) {
- if (isset($staff->remind) && $staff->remind == 1) {
- $staffId = $staff->id ?? 0;
- $ele = $cgId . '-' . $staffId;
- Yii::$app->redis->executeCommand('SADD', [$cacheKey, $ele]);
- }
- }
- }
- $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
- Yii::$app->redis->executeCommand('SADD', [$cacheKey, $cgId]);
- }
- } catch (\Exception $exception) {
- $transaction->rollBack();
- noticeUtil::push("部分门店待入库采购单,重新分配货位出错,原因:" . $exception->getMessage(), '15280215347');
- }
- }
- }
- }
- }
|