$user_id, 'store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1]); if (empty($shop)) { return [ 'code' => 0, 'data' => [ 'shop' => null ] ]; } $user = User::findOne($user_id); return [ 'code' => 0, 'data' => [ 'shop' => $shop, 'user' => [ 'nickname' => $user->nickname, 'avatar_url' => $user->avatar_url ], 'tuan_price' => $user->tuan_price, 'day_price' => $this->dayPrice($shop->id), 'not_price' => $this->notPrice($shop->id), 'total_price' => $this->totalPrice($shop->id), 'order_1' => $this->orderNum(1), 'order_2' => $this->orderNum(2), ] ]; } public function order() { $shop = Shop::findOne(['user_id'=>get_user_id(), 'store_id' => get_store_id(), 'is_delete' => 0,'shop_audit' => 1]); $query = Order::find()->where([ 'is_delete' => 0, 'store_id' => get_store_id(), 'shop_id' => $shop->id, 'is_offline' => 1 ])->andWhere([ 'or', ['is_pay' => 1], ['=', 'pay_type' , 2] ]); if (isset($this->status) && $this->status > -1) { $query->andWhere([ '<>', 'trade_status', Order::ORDER_FLOW_CANCEL ]); } if ($this->status == 1) {//待发货 $query->andWhere([ 'trade_status' => Order::ORDER_FLOW_NO_SEND, ])->andWhere(['or', ['is_pay' => 1], ['pay_type' => 2]]); } if ($this->status == 2) {//待收货 $query->andWhere([ 'trade_status' => Order::ORDER_FLOW_SEND, ]); } if ($this->status == 3) {//已完成 $query->andWhere([ 'trade_status' => Order::ORDER_FLOW_CONFIRM, ]); } $query->andWhere(['is_recycle' => 0]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => 20]); $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->all(); $new_list = []; foreach ($list as $order) { /** * @var Order $order */ $order_detail_list = OrderDetail::findAll(['order_id' => $order->id, 'is_delete' => 0]); $goods_list = []; foreach ($order_detail_list as $order_detail) { $goods = Goods::findOne($order_detail->goods_id); if (!$goods) { continue; } $goods_pic = isset($order_detail->pic) ? $order_detail->pic ?: $goods->getGoodsPic(0)->pic_url : $goods->getGoodsPic(0)->pic_url; $goods_list[] = (object)[ 'goods_id' => $goods->id, 'goods_pic' => $goods_pic, 'goods_name' => $goods->name, 'num' => $order_detail->num, 'price' => $order_detail->total_price, 'attr_list' => json_decode($order_detail->attr), ]; } if ($order->mch_id) { $mch = Mch::findOne($order->mch_id); $mch = [ 'id' => $mch->id, 'name' => $mch->name, 'logo' => $mch->logo, ]; } else { $mch = [ 'id' => 0, 'name' => '平台自营', 'logo' => '', ]; } $orderRefund = OrderRefund::find()->where(['store_id' => $order->store_id, 'order_id' => $order->id])->exists(); // 获取分销佣金 $shopShare = ShopShare::findOne(['order_id' => $order->id, 'type' => 0, 'shop_id' => $shop->id]); $new_list[] = (object)[ 'order_id' => $order->id, 'order_no' => $order->order_no, 'addtime' => date('Y-m-d H:i', $order->created_at), 'goods_list' => $goods_list, 'total_price' => $order->total_price, 'pay_price' => $order->pay_price, 'is_pay' => $order->is_pay, 'is_comment' => $order->is_comment, 'is_offline' => $order->is_offline, 'mch' => $mch, 'type' => $order->type, 'pay_type' => $order->pay_type, 'refund' => $orderRefund, 'shop_price' => $shopShare ? $shopShare->amount : 0, 'trade_status' => $order->trade_status ]; } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $new_list, ], ]; } public function orderNum($status = 1) { $shop = Shop::findOne(['user_id'=>get_user_id(), 'store_id' => get_store_id(), 'is_delete' => 0,'shop_audit' => 1]); $query = Order::find()->where([ 'is_delete' => 0, 'store_id' => get_store_id(), 'shop_id' => $shop->id, 'is_offline' => 1 ])->andWhere([ 'or', ['is_pay' => 1], ['=', 'pay_type' , 2] ]); if ($status == 1) {//待发货 $query->andWhere([ 'trade_status' => Order::ORDER_FLOW_NO_SEND, ])->andWhere(['or', ['is_pay' => 1], ['pay_type' => 2]]); } if ($status == 2) {//待收货 $query->andWhere([ 'trade_status' => Order::ORDER_FLOW_SEND, ]); } $query->andWhere(['is_recycle' => 0]); $count = $query->count(); return $count; } /** * @description: 今日收入 * @param {*} * @return {*} */ private function dayPrice($shop_id) { $start_time = strtotime(date('Y-m-d',time())); $sum = ShopShare::find()->where([ 'shop_id' => $shop_id ])->andWhere([ '>', 'created_at', $start_time ])->andWhere([ '>', 'amount', 0 ])->sum('amount'); return $sum; } /** * @description: 未结算佣金 * @param {*} $shop_id * @return {*} */ private function notPrice($shop_id) { $sum = ShopShare::find()->where([ 'shop_id' => $shop_id, 'status' => 0 ])->sum('amount'); return $sum; } /** * @description: 累计佣金 * @param {*} $shop_id * @return {*} */ private function totalPrice($shop_id) { $sum = ShopShare::find()->where([ 'shop_id' => $shop_id, 'status' => 1 ])->andWhere([ '>', 'amount', 0 ])->sum('amount'); return $sum; } public function confirm($order_id) { $t = \Yii::$app->db->beginTransaction(); try { $order = Order::findOne([ 'store_id' => get_store_id(), 'id' => $order_id, 'trade_status' => [Order::ORDER_FLOW_SEND, Order::ORDER_FLOW_NO_SEND], 'is_delete' => 0, ]); if (!$order) { throw new \Exception('订单不存在'); } //如果订单已经取消 if ($order->apply_delete == Order::ORDER_APPLY_DELETE || $order->trade_status == Order::ORDER_FLOW_CANCEL) { return [ 'code' => 1, 'msg' => '订单已取消或申请取消中,不可核销' ]; } if($order->mch_id){ // 查一下是不是入住商的员工 $mch_staff = MchStaff::findOne(['user_id' => get_user_id(), 'mch_id' => $order->mch_id, 'store_id' => get_store_id(), 'is_delete' => 0,'is_disable' => 0]); $mch = Mch::findOne(['saas_user_id' => get_saas_user_id(), 'id' => $order->mch_id, 'store_id' => get_store_id(), 'is_delete' => 0]); if (empty($mch) && empty($mch_staff)) { return [ 'code' => 1, 'msg' => '您不是入驻商禁止核销' ]; } }else{ // 如果不是自提点管理员判断是否为核销元 $staff = MdStaff::findOne(['saas_user_id'=> get_saas_user_id(), 'store_id' => get_store_id(), 'is_delete' => 0,'is_disable' => 0]); if (empty($staff)) { throw new \Exception('您不是核销员禁止核销'); } } $orderTransitInfo = OrderTransit::find()->where(['order_id' => $order->id, "is_delete" => 0, 'status' => [0, 2]])->one(); if ($orderTransitInfo) { throw new \Exception('云仓订单未发货或已收货'); } $order->clerk_id = get_user_id(); $order->trade_status = Order::ORDER_FLOW_CONFIRM; $order->confirm_time = time(); if ($order->pay_type == 2) { $order->is_pay = 1; $order->pay_time = time(); } if ($order->save()) { if ($staff) { $mdProfit = MdProfit::findOne(['order_id' => $order->id, 'is_send' => 0]); if ($mdProfit) { $mdProfit->clerk_id = $staff->id; $mdProfit->is_send = 1; if (!$mdProfit->save()) { throw new \Exception(json_encode($mdProfit->errors, JSON_UNESCAPED_UNICODE)); } $md = \app\models\Md::findOne($mdProfit->md_id); $md->total_profit += $mdProfit->total_profit; $md->cash_profit += $mdProfit->total_profit; $md->clerk_profit += $mdProfit->clerk_profit; $md->save(); } } //如果存在可转单 // $orderTransitInfo = OrderTransit::find()->where(['order_id' => $order->id, "is_delete" => 0, 'status' => 1])->all(); // if($orderTransitInfo){ // // $cloud_store_token = $this->getCloudStoreToken($this->store_id); // $cloud_store_token = get_merchant_token(0, $order->store_id); // //$cloudInfo = StoreCloud::find()->where(['store_id'=>$this->store_id,"is_delete"=>0])->one(); // if($cloud_store_token) { // foreach($orderTransitInfo as $val){ // $form = new MerchantForm(); // $data = $form->mchPurchaseOrderConfirm(0, $order->store_id, $val->attributes['cloud_order_id']); // if ((int)$data['code'] !== 0) { // return $data; // } // $val->status = 2; // $val->confirm_time = time(); // $val->save(); // if ($val->errors) { // return [ // 'code' => 1, // 'msg' => implode(';', array_values($val->firstErrors)) // ]; // } // } // } else { // return [ // 'code' => 1, // 'msg' => "token信息错误" // ]; // } // } $t->commit(); return [ 'code' => 0, 'msg' => '已确认收货' ]; } else { throw new \Exception('确认收货失败'); } } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function smsSend() { $shop = Shop::findOne(['user_id'=>get_user_id(), 'store_id' => get_store_id(), 'is_delete' => 0,'shop_audit' => 1]); $query = Order::find()->where([ 'is_delete' => 0, 'store_id' => get_store_id(), 'shop_id' => $shop->id, 'is_offline' => 1 ])->andWhere([ 'or', ['is_pay' => 1], ['=', 'pay_type' , 2] ]); $query->andWhere([ 'trade_status' => Order::ORDER_FLOW_SEND ]); $query->andWhere(['is_recycle' => 0]); $list = $query->orderBy('created_at DESC')->all(); foreach ($list as $order) { /** * @var Order $order */ NoticeSend::ShopOffline($order->user_id, $order->mobile, $order->order_no, $order->shop_id); } return [ 'code' => 0, 'msg' => '通知成功' ]; } }