where($where)->field('id,status,user_id')->select(); // 状态 $sucs = 0; $fail = 0; if(!empty($order)) { // 订单更新数据 $upd_data = [ 'status' => 6, 'close_time' => time(), 'upd_time' => time(), ]; foreach($order as $v) { // 开启事务 Db::startTrans(); if(Db::name('Order')->where(['id'=>$v['id'], 'status'=>1])->update($upd_data)) { // 库存回滚 $ret = BuyService::OrderInventoryRollback(['order_id'=>$v['id'], 'order_data'=>$upd_data]); if($ret['code'] == 0) { // 用户消息 MessageService::MessageAdd($v['user_id'], '订单关闭', '订单超时关闭', '订单', $v['id']); // 订单状态日志 OrderService::OrderHistoryAdd($v['id'], $upd_data['status'], $v['status'], '超时关闭', 0, '系统'); // 提交事务 Db::commit(); $sucs++; continue; } } // 事务回滚 Db::rollback(); $fail++; } } return DataReturn('操作成功', 0, ['sucs'=>$sucs, 'fail'=>$fail]); } /** * 订单自动收货 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @datetime 2019-08-18T17:24:05+0800 * @desc 从发货时间开始计算周期 * @param [array] $params [输入参数] */ public static function OrderSuccess($params = []) { // 获取可收货订单 $time = time()-(intval(MyC('common_order_success_limit_time', 21600, true))*60); $where = [ ['delivery_time', '<', $time], ['status', '=', 3], ]; $order = Db::name('Order')->where($where)->field('id,status,user_id')->select(); // 状态 $sucs = 0; $fail = 0; if(!empty($order)) { // 更新订单状态 $upd_data = [ 'status' => 4, 'collect_time' => time(), 'upd_time' => time(), ]; foreach($order as $v) { // 开启事务 Db::startTrans(); if(Db::name('Order')->where(['id'=>$v['id'], 'status'=>3])->update($upd_data)) { // 订单商品积分赠送 $ret = IntegralService::OrderGoodsIntegralGiving(['order_id'=>$v['id']]); if($ret['code'] == 0) { // 订单商品销量增加 $ret = OrderService::GoodsSalesCountInc(['order_id'=>$v['id']]); if($ret['code'] == 0) { // 用户消息 MessageService::MessageAdd($v['user_id'], '订单收货', '订单自动收货成功', '订单', $v['id']); // 订单状态日志 OrderService::OrderHistoryAdd($v['id'], $upd_data['status'], $v['status'], '自动收货', 0, '系统'); // 提交事务 Db::commit(); $sucs++; continue; } } } // 事务回滚 Db::rollback(); $fail++; } } return DataReturn('操作成功', 0, ['sucs'=>$sucs, 'fail'=>$fail]); } /** * 支付日志订单关闭 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2020-07-28 * @desc description * @param [array] $params [输入参数] */ public static function PayLogOrderClose($params = []) { // 时长 $time = time()-(intval(MyC('common_pay_log_order_close_limit_time', 30, true))*60); // 更新关闭 $where = [ ['add_time', '<', $time], ['status', '=', 0], ]; $data = [ 'status' => 2, 'close_time' => time(), ]; $res = Db::name('PayLog')->where($where)->update($data); return DataReturn('操作成功', 0, $res); } } ?>