12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\admin\service\order;
- use app\model\Order;
- use app\model\OrderSheet;
- use app\model\SysDept;
- use support\Db;
- use support\Redis;
- class OrderService
- {
- /**
- * @Desc 自动确认收货
- * @Author Gorden
- * @Date 2024/4/11 16:09
- *
- * @return void
- */
- public static function AutomaticReceipt()
- {
- try {
- Db::beginTransaction();
- $timeUnix = strtotime("-7 days");
- $orders = Order::where('order_status_system', 'SIGNED')
- ->where('order_addtimes', '<', $timeUnix)
- ->get();
- foreach ($orders as $order) {
- // 订单主表
- Order::where('order_id', $order->order_id)->update([
- // 'order_is_complete' => 'Y',
- 'order_status_system' => 'CONFIRM'
- ]);
- // 订单详情表
- OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CONFIRM']);
-
- // 7天后自动完成 order_is_complete=Y
- $redis = Redis::connection();
- $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+7 days"));
- $redis->sadd($key, $order->order_id);
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- }
- }
- public static function checkPayingOrder()
- {
- try {
- Db::beginTransaction();
- $timeUnix = strtotime("-30 minutes");
- $orders = Order::where('order_status_system', 'PAYING')
- ->where('order_addtimes', '<', $timeUnix)
- ->get();
- foreach ($orders as $order) {
- // 订单主表
- Order::where('order_id', $order->order_id)->update([
- 'order_category' => 'CANCEL',
- 'order_status_system' => 'CANCEL',
- 'order_status_payment' => 'CANCEL'
- ]);
- // 订单详情表
- OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CANCEL']);
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- }
- }
- public static function generateWriteOffData($params) {
- return [
- 'charge'=>[
- 'charge_amount'=>1,
- 'charge_content'=>$params['order_remark'] ?? '',
- 'charge_user_id'=>$params['write_off_member_id'],
- 'charge_premises'=>$params['dept_premises_id'],
- ],
- 'member_id'=>$params['join_order_member_id']
- ];
- }
- }
|