| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\common\controllers;
- use app\jobs\CreatedCloudGoodsUpdateLog;
- use app\models\Admin;
- use app\models\AgentFrontBind;
- use app\models\AgentFrontCentralizeGoods;
- use app\models\AgentFrontCentralizeGoodsCancelLog;
- use app\models\AgentFrontCentralizeGoodsExt;
- use app\models\AgentFrontCentralizeGoodsLog;
- use app\models\CloudGoodsUpdateLog;
- use app\models\District;
- use app\models\DriverLineOrder;
- use app\models\Goods;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\PurchaseOrder;
- use app\models\SaaSLeaguePriceLog;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\StoreCloud;
- use app\models\Supplier;
- use app\models\User;
- use app\models\VerifyCardSale;
- use app\modules\admin\models\GoodsForm;
- use app\modules\admin\models\MerchantForm;
- use app\modules\admin\models\OrderRevokeForm;
- use app\utils\Notice\NoticeSend;
- use app\utils\PrintOrder;
- use yii\web\Controller;
- use app\models\OrderTransit;
- /**
- * 微信回调类
- * Class WechatNotifyController
- * @package app\modules\common\controllers
- */
- class CloudCallbackController extends Controller
- {
- public function actionIndex(){
- $post = post_params();
- $content = Option::get('cloud', 0, 'saas');
- $contentParams = json_decode($content['value'],true);
- $data = [];
- $data['action'] = $post['action'];
- $data['time'] = $post['time'];
- $data['name'] = $contentParams['name'];
- $data['pwd'] = md5(md5($contentParams['pwd']));
- $data['order_id'] = $post['order_id'];
- if ($data['action'] === 'send_order_purchase' || $data['action'] === 'send_order') {
- $data['express_name'] = $post['express_name'];
- $data['express_no'] = $post['express_no'];
- $data['send_type'] = $post['send_type'];
- }
- if ($data['action'] === 'order_centralized') {
- $data['mch_id'] = $post['mch_id'];
- $data['supplier_id'] = $post['supplier_id'];
- if ($post['type']) {
- $data['type'] = $post['type'];
- $data['province_id'] = $post['province_id'];
- $data['city_id'] = $post['city_id'];
- $data['district_id'] = $post['district_id'];
- }
- }
- if ($data['action'] === 'centralized_handle') {
- $data['status'] = $post['status'];
- }
- if ($data['action'] === 'update_cloud_goods') {
- $data['goods_id'] = $post['goods_id'];
- $data['price_open'] = $post['price_open'];
- $data['supplier_id'] = $post['supplier_id'];
- }
- if ($data['action'] === 'goods_bind_supplier') {
- $data['mch_id'] = $post['mch_id'];
- }
- if ($data['action'] === 'order_cancel_result') {
- $data['supplier_id'] = $post['supplier_id'];
- $data['type'] = $post['type'];
- $data['status'] = $post['status'];
- }
- if ($data['action'] === 'order_goods_cancel') {
- $data['supplier_id'] = $post['supplier_id'];
- $data['goods_id'] = $post['goods_id'];
- $data['md_id'] = $post['md_id'];
- $data['num'] = $post['num'];
- }
- if($this->setSign($data) != $post['sign']){
- $message = [];
- $message['code'] = 1;
- $message['msg'] = "验证失败";
- debug_log("验证失败");
- return $this->asJson($message);
- exit;
- }
- if ($data['action'] === 'send_order_purchase' || $data['action'] === 'send_order') {
- if ($data['action'] === 'send_order_purchase') {
- $orderTransitInfo = OrderTransit::findOne(['cloud_order_id'=>$data['order_id'],'is_delete'=>0]);
- } elseif ($data['action'] === 'send_order') {
- $orderTransitInfo = PurchaseOrder::findOne(['cloud_order_id'=>$data['order_id'],'is_delete'=>0]);
- }
- if(!$orderTransitInfo){
- $message = [];
- $message['code'] = 1;
- $message['msg'] = "订单信息不存在";
- return $this->asJson($message);
- exit;
- }
- if($data['action'] === 'send_order_purchase' && $orderTransitInfo->status != 0 && !intval($post['update_send_info'])){
- $message = [];
- $message['code'] = 1;
- $message['msg'] = "订单信息有误";
- return $this->asJson($message);
- exit;
- }
- if($data['action'] !== 'send_order_purchase' && $orderTransitInfo->trade_status != 0 && !intval($post['update_send_info'])){
- $message = [];
- $message['code'] = 1;
- $message['msg'] = "订单信息有误";
- return $this->asJson($message);
- exit;
- }
- $orderTransitInfo->express_no = $post['express_no'];
- if ($data['action'] === 'send_order_purchase') {
- if (!intval($post['update_send_info'])) {
- $orderTransitInfo->status = 1; //已发货
- }
- $orderTransitInfo->send_type = $post['send_type'];
- $orderTransitInfo->express_name = $post['express_name'];
- } elseif ($data['action'] === 'send_order') {
- if (!intval($post['update_send_info'])) {
- $orderTransitInfo->trade_status = PurchaseOrder::ORDER_FLOW_SEND; //已发货
- $orderTransitInfo->send_time = time();
- }
- $orderTransitInfo->express = $post['express_name'];
- }
- if(!$orderTransitInfo->save()){
- $message = [];
- $message['code'] = 1;
- $message['msg'] = "修改失败";
- }else{
- if ($data['action'] === 'send_order_purchase') {
- $order = Order::findOne($orderTransitInfo->order_id);
- $order_id = $orderTransitInfo->order_id;
- $order_transit = OrderTransit::find()->where(['order_id' => $order_id])
- ->andWhere(['>=', 'status', 1])
- ->select('order_detail_ids')->asArray()->all();//;
- // $order_transit_count = $order_transit;
- $order_transit_count = 0;
- foreach ($order_transit as $transit) {
- $order_detail_ids = count(json_decode($transit['order_detail_ids']));
- $order_transit_count += $order_detail_ids;
- }
- $order_detail = OrderDetail::find()->where(['order_id' => $order_id])->count();
- if ($order_transit_count >= $order_detail) {
- $order->express = $post['express_name'] ?? '';
- $order->express_no = $post['express_no'] ?? '';
- if (!intval($post['update_send_info'])) {
- $order->trade_status = 2;
- $order->send_time = time();
- }
- }
- if (!$order->save()) {
- $message['code'] = 1;
- $message['msg'] = "修改失败";
- return $this->asJson($message);
- }
- }
- $message = [];
- $message['code'] = 0;
- $message['msg'] = "success";
- }
- return $this->asJson($message);
- exit;
- }
- if ($data['action'] === 'order_centralized') {
- $cloud_mch_id = $data['mch_id'];
- $supplier_id = $data['supplier_id'];
- $supplier = Supplier::findOne(['cloud_supplier_id' => $supplier_id]);
- $store_cloud = StoreCloud::findOne(['cloud_store_id' => $cloud_mch_id])->store_id;
- $store = Store::findOne($store_cloud);
- debug_log($cloud_mch_id);
- // $option = Option::get('agency_price_config', 0, 'saas');
- // if ($option['value']) {
- // $option = json_decode($option['value'], true);
- // }
- // $model_type = $option['model_type'] ?: 0;
- $md_id = 0;
- //批发
- //这里应该要注释了 说是集采订单只能转单了
- if ($data['type']) {
- $supplier_bind_admin_id = AgentFrontBind::find()->where([
- 'type' => AgentFrontBind::TYPE_SUPPLIER,
- 'type_id' => $supplier->id,
- 'status' => 1,
- 'is_delete' => 0,
- ])->select('front_agent_admin_id')->column();
- if (!$supplier_bind_admin_id) {
- $message['code'] = 1;
- $message['msg'] = "供货商未找到对应的前置仓代理";
- return $this->asJson($message);
- }
- $province_id = $data['province_id'];
- $city_id = $data['city_id'];
- $district_id = $data['district_id'];
- $admin = Admin::find()
- ->where(['is_delete' => 0])
- ->andWhere([
- 'area_level' => 1,
- 'province_id' => $province_id,
- 'city_id' => $city_id,
- 'district_id' => $district_id,
- 'type' => Admin::ADMIN_TYPE_FRONT_AGENT,
- 'id' => $supplier_bind_admin_id
- ])->one();
- if (empty($admin)) {
- $admin = Admin::find()
- ->where(['is_delete' => 0])
- ->andWhere([
- 'area_level' => 2,
- 'province_id' => $province_id,
- 'city_id' => $city_id,
- 'type' => Admin::ADMIN_TYPE_FRONT_AGENT,
- 'id' => $supplier_bind_admin_id
- ])->one();
- if (empty($admin)) {
- $admin = Admin::find()
- ->where(['is_delete' => 0])
- ->andWhere([
- 'area_level' => 3,
- 'province_id' => $province_id,
- 'type' => Admin::ADMIN_TYPE_FRONT_AGENT,
- 'id' => $supplier_bind_admin_id
- ])->one();
- }
- }
- } else {
- //转单
- $province_id = $store->province_id;
- $city_id = $store->city_id;
- $district_id = $store->district_id;
- debug_log(['data' => $data, 'post' => $post]);
- //判断门店是否绑定的有前置仓信息
- // $orderTransit = OrderTransit::findOne(['cloud_order_id' => $data['order_id']]);
- // $store_order = Order::findOne($orderTransit->order_id);
- $md_id = $post['md_id'];
- $supplier_bind_admin_id = AgentFrontBind::find()->where([
- 'type' => AgentFrontBind::TYPE_SUPPLIER,
- 'type_id' => $supplier->id,
- 'status' => 1,
- 'is_delete' => 0,
- ])->select('front_agent_admin_id')->column();
- if (!$supplier_bind_admin_id) {
- $message['code'] = 1;
- $message['msg'] = "供货商未找到对应的前置仓代理";
- return $this->asJson($message);
- }
- if ($md_id > 0) {
- $bind_agent_admin = AgentFrontBind::findOne([
- 'type' => AgentFrontBind::TYPE_STORE,
- 'status' => 1,
- 'is_delete' => 0,
- 'md_id' => $md_id,
- 'front_agent_admin_id' => $supplier_bind_admin_id
- ]);
- }
- if (!isset($bind_agent_admin)) {
- $bind_agent_admin = AgentFrontBind::findOne([
- 'type' => AgentFrontBind::TYPE_STORE,
- 'type_id' => $store->id,
- 'status' => 1,
- 'is_delete' => 0,
- 'md_id' => 0,
- 'front_agent_admin_id' => $supplier_bind_admin_id
- ]);
- }
- $admin = Admin::findOne(['id' => $bind_agent_admin->front_agent_admin_id]);
- }
- // if ((int)$model_type === 0) {
- // $admin = Admin::find()
- // ->where(['is_delete' => 0])
- // ->andWhere([
- // 'area_level' => 2,
- // 'province_id' => $province_id,
- // 'city_id' => $city_id
- // ])->one();
- // } else {
- // $admin = Admin::find()
- // ->where(['is_delete' => 0])
- // ->andWhere([
- // 'area_level' => 1,
- // 'province_id' => $province_id,
- // 'city_id' => $city_id,
- // 'district_id' => $district_id
- // ])->one();
- // }
- $district = District::find()->where(['id' => [$province_id, $city_id, $district_id]])->select('name')->column();
- $district = implode(' ', $district);
- $message['code'] = 1;
- $message['msg'] = "未找到" . $district . "区域下的前置仓代理";
- if ($admin) {
- $message = [];
- $message['code'] = 0;
- $message['msg'] = "success";
- $message['data'] = [
- 'admin_id' => $admin->id,
- 'md_id' => $md_id
- ];
- }
- debug_log(json_encode($message));
- return $this->asJson($message);
- exit;
- }
- if ($data['action'] === 'centralized_handle') {
- $order_id = json_decode($data['order_id'], true);
- if (!empty($order_id) && is_array($order_id)) {
- $purchase = PurchaseOrder::find()->where(['cloud_order_id' => $order_id, 'is_delete' => 0])->all();
- foreach ($purchase as $item) {
- $item->centralized_status = ((int)$data['status'] + 1);
- if ((int)$data['status'] === 3) {
- $item->trade_status = 2;
- }
- $item->save();
- }
- }
- $message = [];
- $message['code'] = 0;
- $message['msg'] = "success";
- return $this->asJson($message);
- exit;
- }
- if ($data['action'] === 'send_order_purchase_group') {
- $order_id = $data['order_id'];
- $order = OrderTransit::findOne(['cloud_order_id' => $order_id]);
- $order->status = 1;
- // $order->confirm_time = time();
- $order->save();
- $order_transit = OrderTransit::find()->where(['order_id' => $order->order_id])
- ->andWhere(['>=', 'status', 1])
- ->select('order_detail_ids')->asArray()->all();//;
- $order_transit_count = 0;
- foreach ($order_transit as $transit) {
- $order_detail_ids = count(json_decode($transit['order_detail_ids']));
- $order_transit_count += $order_detail_ids;
- }
- $order_detail = OrderDetail::find()->where(['order_id' => $order->order_id])->count();
- debug_log($order_transit_count . '-----' . $order_detail, 'cloud.log');
- if ($order_transit_count >= $order_detail) {
- $order = Order::findOne($order->order_id);
- $order->trade_status = 2;
- $order->send_time = time();
- if (!$order->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => json_encode($order->errors)
- ]);
- }
- }
- $message = [];
- $message['code'] = 0;
- $message['msg'] = "success";
- return $this->asJson($message);
- }
- if ($data['action'] === 'update_cloud_goods') {
- $cloud_goods_id = $data['goods_id'];
- $cloud_supplier_id = $data['supplier_id'];
- $price_open = $data['price_open'];
- $num_open = intval($post['num_open']);
- $store_id = (int)$post['store_id'];
- $andWhere = [];
- if($store_id){
- $andWhere['store_id'] = $store_id;
- }
- $goods = Goods::find()->where(['cloud_goods_id' => $data['goods_id'], 'is_delete' => 0])
- ->andWhere($andWhere)
- ->andWhere(['OR', ['is', 'is_wholesale', null], ['<=', 'is_wholesale', 0]])->asArray()->all();
- foreach ($goods as $item) {
- //获取商城是否设置云仓产品自动更新
- // $cloud_is_update = Option::get('cloud_is_update', $item['store_id'], 'store')['value'];
- $log = CloudGoodsUpdateLog::findOne(['cloud_goods_id' => $cloud_goods_id, 'store_id' => $item['store_id']]) ?? new CloudGoodsUpdateLog();
- $log->cloud_supplier_id = $cloud_supplier_id;
- $log->cloud_goods_id = $cloud_goods_id;
- $log->store_id = $item['store_id'];
- $log->goods_id = $item['id'];
- $log->is_update = 0;
- $log->is_audit = $price_open;
- $log->status = (int)$item['status'];
- $log->created_at = time();
- $log->updated_at = '0';
- $log->save();
- debug_log(json_encode($log->errors));
- }
- // $cloud_goods_id = $data['goods_id'];
- $form = new GoodsForm();
- //找出商品未审核或者未更新的产品
- $CloudGoodsUpdateLog = CloudGoodsUpdateLog::find()->where(['cloud_goods_id' => $cloud_goods_id, 'updated_at' => 0])->andWhere($andWhere)->asArray()->all();
- foreach ($CloudGoodsUpdateLog as $value) {
- $goods_info = Goods::findOne(['cloud_goods_id' => $cloud_goods_id, 'store_id' => $value['store_id'], 'is_wholesale' => 0]);
- $goods_info->status = 0;
- $goods_info->save();
- //判断是否开启自动更新
- $cloud_is_update = Option::get('cloud_is_update', $value['store_id'], 'store')['value'];
- if ($data['price_open'] || intval($cloud_is_update)) {
- //直接通过审核(目前只有点击审核通过时才会调用此事件)
- $item = CloudGoodsUpdateLog::findOne($value['id']);
- $item->is_audit = 1;
- $item->updated_at = time();
- //更新产品逻辑
- if ($value['goods_id']) {
- $StoreCloud = StoreCloud::findOne(['store_id' => $value['store_id'], 'is_delete' => 0, 'is_enable' => 1]);
- $form->id = $value['cloud_goods_id'];
- $form->store_id =$value['store_id'];
- $goodsInfo = $form->saveCloudGoods($num_open);
- $merchantForm = new MerchantForm();
- $merchantForm->token_stroe_cloud_id = $StoreCloud->id;
- debug_log('store_id' . $value['store_id']);
- $result = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'], $goodsInfo['goods_id'], $value['store_id']);
- if ((int)$result['code'] !== 0) {
- return $result;
- }
- $item->is_update = 1;
- }
- $item->save();
- }
- }
- $message['code'] = 0;
- $message['msg'] = "success";
- return $this->asJson($message);
- }
- //赤店返回绑定该前置仓的供货商
- if ($data['action'] === 'goods_bind_supplier') {
- $store_cloud = StoreCloud::findOne(['cloud_store_id' => $data['mch_id'], 'is_delete' => 0]);
- if ($store_cloud) {
- $agent_front_bind = AgentFrontBind::findOne(['type' => 1, 'status' => 1, 'type_id' => $store_cloud->store_id, 'is_delete' => 0]);
- if ($agent_front_bind) {
- $front_agent_admin_id = $agent_front_bind->front_agent_admin_id;
- $supplier_id = AgentFrontBind::find()
- ->where(['type' => 0, 'status' => 1, 'is_delete' => 0, 'front_agent_admin_id' => $front_agent_admin_id])
- ->select('type_id')->column();
- $supplier_id = Supplier::find()->where(['id' => $supplier_id, 'is_delete' => 0])->select('cloud_supplier_id')->column();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $supplier_id
- ]);
- } else {
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [0]
- ]);
- }
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未查找到用户信息'
- ]);
- }
- //供货商同意取消订单(可能是三方操作)
- if ($data['action'] === 'order_cancel_result') {
- if (intval($data['status']) === 2) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '完成。已拒绝'
- ]);
- }
- //如果已经转单 就调用取消接口
- $orderTransit = OrderTransit::findOne(['cloud_order_id' => $data['order_id'], 'is_delete' => 0]);
- if (!$orderTransit) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未查找到云仓订单'
- ]);
- }
- if (intval($orderTransit->status) == -1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '订单已取消'
- ]);
- }
- $order = Order::findOne($orderTransit->order_id);
- $form = new OrderRevokeForm();
- $form->order_id = $order->id;
- $form->delete_pass = true;
- $form->user_id = $order->user_id;
- $form->store_id = $order->store_id;
- $res = $form->save();
- if ($res['code'] == 0) {
- VerifyCardSale::cancelCard($order);
- $order->save();
- $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $order->id])->goods_id);
- if ($order->order_type == Order::ORDER_TYPE_Adopt) {
- NoticeSend::OrderCancel($order->user_id, $order->mobile, $order->order_no, $order->pay_price, $goods->name, 1);
- }else{
- NoticeSend::OrderCancel($order->user_id, $order->mobile, $order->order_no, $order->pay_price, $goods->name, 0);
- }
- // 订单打印
- if ((int)$order->md_id === -1 || (int)$order->md_id === 0 || !isset($order->md_id)) {
- $order->md_id = 0;
- }
- $printer_order = new PrintOrder($order->store_id, $order->id, 'confirm', 0, $order->md_id, 0, $order['mch_id']);
- $printer_order->is_refund = true;
- $printer_order->print_order();
- if($order->take_price > 0){
- $user = User::findOne($order->user_id);
- $saas_user = SaasUser::findOne(['mobile' => $user->binding]);
- if($saas_user){
- $take_price = $order->take_price;
- $before = $saas_user->league_price;
- $saas_user->updateCounters(['league_price' => floatval($take_price)]);
- \app\models\SaaSLeaguePriceLog::setLeaguePriceLog(
- $order->store_id,
- $saas_user->id,
- $take_price,
- $before,
- \app\models\SaaSLeaguePriceLog::TYPE_CANCEL,
- \app\models\SaaSLeaguePriceLog::SEND_TYPE,
- \app\models\SaaSLeaguePriceLog::ROLE_USER,
- $order->id
- );
- }
- }
- $orderTransit->status = -1;
- $orderTransit->save();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '退款完成。'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '退款失败。'
- ]);
- }
- //订单商品取消
- if ($data['action'] === 'order_goods_cancel') {
- // $cloud_order_goods_cancel = cache()->get('cloud_order_goods_cancel');
- // if ($cloud_order_goods_cancel) {
- // return $this->asJson([
- // 'code' => 0,
- // 'msg' => '请稍后重试。'
- // ]);
- // } else {
- // cache()->set('cloud_order_goods_cancel', $data['order_id'], 3);
- // }
- $goods_log = AgentFrontCentralizeGoodsLog::find()->where(['cloud_order_id' => $data['order_id']])
- ->select('centralize_goods_id')->column();
- if (!$goods_log) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '获取商品失败'
- ]);
- }
- debug_log(['goods_log' => $goods_log], '20250721.log');
- debug_log(['post' => $post], '20250721.log');
- $attr = json_decode($post['attr'], true);
- $attr_id_arr = array_column($attr, 'attr_id');
- sort($attr_id_arr);
- //找到对应的商品 进行扣减分拣数量 这里正常来讲只会找到一个
- $agentFrontCentralizeGoodsArray = AgentFrontCentralizeGoods::find()->where([
- 'id' => $goods_log,
- 'cloud_goods_id' => $data['goods_id']
- ])->asArray()->all();
- if (!$agentFrontCentralizeGoodsArray) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '获取商品失败AgentFrontCentralizeGoods'
- ]);
- }
- debug_log(['agentFrontCentralizeGoodsArray' => $agentFrontCentralizeGoodsArray], '20250721.log');
- $centralize_goods_id = 0;
- foreach ($agentFrontCentralizeGoodsArray as $centralizeGoodsItem) {
- $centralizeGoodsItemAttr = json_decode($centralizeGoodsItem['attr'], true);
- sort($centralizeGoodsItemAttr);
- if (!array_diff($attr_id_arr, $centralizeGoodsItemAttr)) {
- $centralize_goods_id = $centralizeGoodsItem['id'];
- }
- }
- debug_log(['centralize_goods_id' => $centralize_goods_id], '20250721.log');
- $agentFrontCentralizeGoods = AgentFrontCentralizeGoods::findOne($centralize_goods_id);
- if (!$agentFrontCentralizeGoods) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '获取商品失败AgentFrontCentralizeGoods'
- ]);
- }
- ///
- $agentFrontCentralizeGoodsExt = AgentFrontCentralizeGoodsExt::findOne([
- 'centralize_goods_id' => $centralize_goods_id,
- 'md_id' => $data['md_id']
- ]);
- if (!$agentFrontCentralizeGoodsExt) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '获取商品失败AgentFrontCentralizeGoodsExt'
- ]);
- }
- //如果是待分拣状态那么就减去对应的数量
- if (intval($agentFrontCentralizeGoodsExt->status) === AgentFrontCentralizeGoodsExt::STATUS_WAIT_SORTING) {
- if ($agentFrontCentralizeGoodsExt->goods_num - $data['num'] >= $agentFrontCentralizeGoodsExt->sorting_num) {
- if (intval($agentFrontCentralizeGoods->status) === AgentFrontCentralizeGoods::STATUS_SORTING) {
- if ($agentFrontCentralizeGoods->goods_num - $data['num'] >= $agentFrontCentralizeGoods->sorting_num) {
- $agentFrontCentralizeGoods->updateCounters(['goods_num' => -$data['num']]);
- $agentFrontCentralizeGoodsExt->updateCounters(['goods_num' => -$data['num']]);
- }
- }
- }
- }
- $cancel_log = new AgentFrontCentralizeGoodsCancelLog();
- $cancel_log->front_admin_id = $agentFrontCentralizeGoods->front_admin_id;
- $cancel_log->supplier_id = $data['supplier_id'];
- $cancel_log->centralize_goods_id = $agentFrontCentralizeGoods->id;
- $cancel_log->cloud_order_id = $data['order_id'];
- $cancel_log->md_id = $data['md_id'];
- $cancel_log->goods_num = $data['num'];
- if (!$cancel_log->save()) {
- debug_log(['centralize_goods_id' => $cancel_log->errors], '20250721.log');
- };
- ///这里需要增加一下DriverLineOrder中的拦截的商品数量
- $driverLineOrder = DriverLineOrder::findOne(['centralize_goods_ext_id' => $agentFrontCentralizeGoodsExt->id, 'md_id' => $data['md_id']]);
- if (!$driverLineOrder) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '获取商品失败DriverLineOrder'
- ]);
- }
- $driverLineOrder->updateCounters(['cancel_goods_num' => $data['num']]);
- $cancel_log->driver_line_order_id = $driverLineOrder->id;
- $cancel_log->save();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '完成。操作完成'
- ]);
- }
- }
- public static function setSign($data)
- {
- ksort($data);
- $str = '';
- foreach($data as $key => $val) {
- $str .= $str ? '&'.$key.'='.$val : $key.'='.$val;
- }
- return md5($str);
- }
- }
|