diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 05eb950..59aec11 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -5,6 +5,7 @@ namespace app\api\controller; use app\admin\validate\tools\GenerateTableValidate; use app\admin\logic\tools\GeneratorLogic; use app\common\service\pay\PayService; +use app\common\service\wechat\WeChatMnpService; use app\common\service\wechat\WeChatOaService; use Webman\Config; use Webman\RedisQueue\Redis; @@ -17,6 +18,9 @@ class IndexController extends BaseApiController public function index() { + $app=new WeChatMnpService(); + $a= $app->delivery(); + d($a); $queue = 'send-mail'; // 数据,可以直接传数组,无需序列化 $data = ['to' => 'tom@gmail.com', 'content' => 'hello']; diff --git a/app/api/controller/order/OpurchaseOrderController.php b/app/api/controller/order/OpurchaseOrderController.php index 94ac6cd..fcdf43f 100644 --- a/app/api/controller/order/OpurchaseOrderController.php +++ b/app/api/controller/order/OpurchaseOrderController.php @@ -2,8 +2,13 @@ namespace app\api\controller\order; +use app\admin\logic\operation\OpurchaseclassLogic; +use app\admin\validate\operation\OpurchaseclassValidate; use app\api\logic\order\OrderLogic; use app\api\controller\BaseApiController; +use app\api\lists\operation\OpurchaseclassLists; +use app\common\model\goods\Goods; +use app\common\model\opurchase\Opurchaseinfo; use Webman\RedisQueue\Redis; /** @@ -12,6 +17,64 @@ use Webman\RedisQueue\Redis; class OpurchaseOrderController extends BaseApiController { + /** + * @notes 获取采购订单列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 11:26 + */ + public function lists() + { + return $this->dataLists(new OpurchaseclassLists()); + } + + /** + * @notes 获取采购订单详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/27 11:26 + */ + public function detail() + { + $params = (new OpurchaseclassValidate())->goCheck('detail'); + $result = OpurchaseclassLogic::detail($params); + return $this->data($result); + } + + /** + * @notes 采购子订单详情 + */ + public function sub_orders() + { + $id = $this->request->get('id'); + $page_no = $this->request->get('page_no', 1); + $result = OpurchaseclassLogic::sub_detail($id, $page_no); + return $this->data($result); + } + + /** + * @notes 采购订单总商品列表 + */ + public function opurchaseinfo_list() + { + $id = $this->request->get('id'); + $page_no = $this->request->get('page_no', 1); + $res = Opurchaseinfo::where('pid', $id)->page($page_no, 25)->select()->each(function ($item) { + $find = Goods::where('id', $item['goods'])->with('unitName')->find(); + if($find){ + $item['goods_name'] = $find['name']; + $item['unit_name'] = $find['unit_name']; + } + + }); + $data['count'] = Opurchaseinfo::where('pid', $id)->count(); + $data['lists'] = $res?->toArray(); + $data['page_no'] = $page_no; + $data['page_siz'] = 15; + return $this->success('ok', $data); + } + + public function checkOrder(){ $params=$this->request->get(); diff --git a/app/api/lists/operation/OpurchaseclassLists.php b/app/api/lists/operation/OpurchaseclassLists.php new file mode 100644 index 0000000..98ac911 --- /dev/null +++ b/app/api/lists/operation/OpurchaseclassLists.php @@ -0,0 +1,75 @@ + ['merchant', 'order_arr', 'number'], + 'between_time' => 'create_time', + ]; + } + + + /** + * @notes 获取采购订单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/27 11:26 + */ + public function lists(): array + { + return Opurchaseclass::where($this->searchWhere) + ->where('merchant',Request()->userInfo['merchant']['mer_id']) + ->field(['id', 'merchant', 'order_arr', 'cart_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'paid','create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->each(function($data){ + $data['order_count']=count(explode(',',$data['order_arr'])); + // $merchant = Merchant::field('mer_name')->where('mer_id',$data['merchant'])->findOrEmpty(); + // $data['merchant_name'] = !$merchant->isEmpty() ? $merchant['mer_name'] : ''; + }) + ->toArray(); + } + + + /** + * @notes 获取采购订单数量 + * @return int + * @author likeadmin + * @date 2024/04/27 11:26 + */ + public function count(): int + { + return Opurchaseclass::where($this->searchWhere) + ->where('merchant',Request()->userInfo['merchant']['mer_id']) + ->count(); + } + +} \ No newline at end of file diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 26e0473..547d1cf 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -138,18 +138,25 @@ class OrderLogic extends BaseLogic } $mer_id = $user['merchant']['mer_id']; $where1 = ['paid' => 1]; - $cartId = Cashierclass::where('merchant', $mer_id)->whereDay('create_time')->where($where1)->column('cart_id'); - if (empty($cartId)) { - self::setError('没有购物车信息'); - return false; - } - $order_id = Cashierclass::where('merchant', $mer_id)->whereDay('create_time')->where($where1)->column('id'); + $arrs = Cashierclass::where('merchant', $mer_id)->whereDay('create_time')->where($where1)->column('cart_id,id,address_id'); + + // $order_id = Cashierclass::where('merchant', $mer_id)->whereDay('create_time')->where($where1)->column('id'); $cart_arr = []; - foreach ($cartId as $k => $v) { - $arr = explode(',', $v); + $order_id = []; + foreach ($arrs as $k => $v) { + if (empty($v['cart_id'])) { + self::setError('没有购物车信息'); + return false; + } + if (empty($v['address_id'])) { + self::setError('请先设置配送地址'); + return false; + } + $arr = explode(',',$v['cart_id']); foreach ($arr as $kk => $vv) { $cart_arr[] = $vv; } + $order_id[] = $v['id']; } $where = ['is_pay' => 1, 'is_fail' => 0]; $cart_select = Cart::whereIn('cart_id', $cart_arr)->where($where)->field('goods_id as goods,cart_num')->select()->toArray(); @@ -206,6 +213,7 @@ class OrderLogic extends BaseLogic $goods_list = $orderInfo['cart_list']; foreach ($goods_list as $k => $v) { $goods_list[$k]['nums'] = $v['cart_num']; + $goods_list[$k]['pid'] = $order->id; } (new Opurchaseinfo())->saveAll($goods_list); // $merchant->mer_money = bcsub($merchant->mer_money, $_order['total'], 2); diff --git a/app/common/lists/BaseDataLists.php b/app/common/lists/BaseDataLists.php index 3a37109..901ace1 100644 --- a/app/common/lists/BaseDataLists.php +++ b/app/common/lists/BaseDataLists.php @@ -104,7 +104,7 @@ abstract class BaseDataLists implements ListsInterface } $endTime = $this->request->get('end_time'); if($endTime){ - $this->endTime = $startTime??strtotime($endTime); + $this->endTime = strtotime($endTime); } $this->start = $this->request->get('start'); $this->end = $this->request->get('end'); diff --git a/app/common/service/wechat/WeChatMnpService.php b/app/common/service/wechat/WeChatMnpService.php index 38da47b..6883ec6 100644 --- a/app/common/service/wechat/WeChatMnpService.php +++ b/app/common/service/wechat/WeChatMnpService.php @@ -97,5 +97,24 @@ class WeChatMnpService ]); } - -} \ No newline at end of file + /** + * @notes 发货 + */ + public function delivery() + { + $accessToken = $this->app->getAccessToken(); + $token = $accessToken->getToken(); + return $this->app->getClient()->postJson('product/delivery/send?access_token=' . $token, [ + 'order_id' => 'PF171564998868869065', + ])->toArray(); + } + /** + * @notes 获取access_token + * @return string + */ + public function AccessToken() + { + $accessToken = $this->app->getAccessToken(); + return $accessToken->getToken(); // string + } +}