find($order_id); if (!$order) return false; if (empty($order['attach_values'])) return false; $attach = json_decode($order['attach_values'], true); // 自提订单没有发货操作。 // 当订单为自提方式,赠送机制为订单发货赠送且传入场景为 3=订单完成(自提核销操作) 时 // 调整场景值为2,便于通过后续场景值验证 if ($order['delivery_type'] == Order::DELIVERY_STATUS_SELF && $attach['give_growth_scene'] == 2 && $scene == 3) { $scene = 2; } $this->giveIntegral($order, $attach, $scene); $this->giveGrowth($order, $attach, $scene); return true; } catch (Exception $e) { Log::write('赠送奖励失败:'.$e->getMessage()); return false; } } /** * @Notes: 送积分 * @Author: 张无忌 * @param $order * @param $attach * @param $scene * @return bool * @throws \think\Exception */ private function giveIntegral($order, $attach, $scene) { if ($attach['give_integral_scene'] != $scene) return true; if ($attach['give_integral_num'] <= 0) return true; Db::name('user')->where(['id'=>$order['user_id']])->update([ 'user_integral' => ['inc', $attach['give_integral_num']], 'update_time' => time() ]); $change_type = 1; $channel = AccountLog::order_goods_give_integral; AccountLogLogic::AccountRecord( $order['user_id'], $attach['give_integral_num'], $change_type, $channel, '', $order['id'] ); return true; } /** * @Notes: 送成长值 * @Author: 张无忌 * @param $order * @param $attach * @param $scene * @return bool * @throws \think\Exception */ private function giveGrowth($order, $attach, $scene) { if ($attach['give_growth_scene'] != $scene) return true; if ($attach['give_growth_num'] <= 0) return true; Db::name('user')->where(['id'=>$order['user_id']])->update([ 'user_growth' => ['inc', $attach['give_growth_num']], 'update_time' => time() ]); $change_type = 1; $channel = AccountLog::order_give_growth; AccountLogLogic::AccountRecord( $order['user_id'], $attach['give_growth_num'], $change_type, $channel, '', $order['id'] ); return true; } }