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); } }