1, 'refund_status' => 0])->whereDay('create_time')->group('store_id')->column('store_id'); $purchaseOrderInfo = new PurchaseOrderInfo(); foreach ($store_arr as $store_id) { $purchase_order_info = []; $order_arr = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'store_id' => $store_id])->whereDay('create_time')->column('id'); $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'store_id' => $store_id])->whereDay('create_time')->field('SUM(pay_price) as pay_price,SUM(total_price) as total_price')->find(); $data = [ 'store_id' => $store_id, 'order_arr' => json_encode($order_arr), 'order_id' => getNewOrderId('CG'), 'total' => $price['total_price'], 'actual' => $price['pay_price'], 'money' => $price['pay_price'], 'paid' => 1, 'is_mer' => 1, 'create_time' => time(), 'update_time' => time(), ]; $res = PurchaseOrder::create($data); $info = StoreOrderCartInfo::where('oid', 'in', $order_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select(); foreach ($info as $item) { $arr['oid'] = $res['id']; $arr['store_id'] = $item['store_id']; $arr['product_id'] = $item['product_id']; $arr['price'] = $item['price']; $arr['total_price'] = $item['total_price']; $arr['cart_num'] = $item['cart_num']; $arr['status'] = 1; $purchase_order_info[] = $arr; } $purchaseOrderInfo->saveAll($purchase_order_info); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 合并今日平台订单 * @param array $params * @return bool * @author admin * @date 2024/08/01 16:32 */ public static function platformTodayOrder() { Db::startTrans(); try { $purchaseOrderInfo = new PurchaseOrderInfo(); $purchase_order_info=[]; $order_arr = PurchaseOrder::whereDay('create_time')->where('is_mer',1)->column('id'); $price = PurchaseOrder::whereDay('create_time')->field('SUM(actual) as pay_price,SUM(total) as total_price')->find(); $data = [ 'store_id' => 0, 'order_arr' => json_encode($order_arr), 'order_id' => getNewOrderId('PT'), 'total' => $price['total_price'], 'actual' => $price['pay_price'], 'money' => $price['pay_price'], 'paid' => 1, 'is_mer' => 2, 'create_time' => time(), 'update_time' => time(), ]; $res = PurchaseOrder::create($data); $info = PurchaseOrderInfo::where('oid', 'in', $order_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select(); foreach ($info as $item) { $arr['oid'] = $res['id']; $arr['store_id'] = $item['store_id']; $arr['product_id'] = $item['product_id']; $arr['price'] = $item['price']; $arr['total_price'] = $item['total_price']; $arr['cart_num'] = $item['cart_num']; $arr['status'] = 1; $purchase_order_info[] = $arr; } $purchaseOrderInfo->saveAll($purchase_order_info); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); d($e); self::setError($e->getMessage()); return false; } } /** * @notes 删除采购订单 * @param array $params * @return bool * @author admin * @date 2024/08/01 16:32 */ public static function delete(array $params): bool { return PurchaseOrder::destroy($params['id']); } /** * @notes 获取采购订单详情 * @param $params * @return array * @author admin * @date 2024/08/01 16:32 */ public static function detail($id): array { $data= PurchaseOrder::findOrEmpty($id)->toArray(); if($data){ if($data['store_id']){ $data['system_store']=SystemStore::where('id',$data['store_id'])->value('name'); }else{ $data['system_store']='平台'; } switch ($data['storage']) { case 0: $data['storage_name'] = '未入库'; break; case 1: $data['storage_name'] = '部分入库'; break; case 2: $data['storage_name'] = '已入库'; break; default: $data['storage_name'] = '未入库'; } } return $data; } }