model = new \app\agent\model\order\Taxi(); // 加载配置 $wechat = sys_config('','wechat'); $this->wechat = Factory::miniProgram([ 'app_id' => $wechat['mini_appid'], 'secret' => $wechat['mni_secret_key'], 'response_type' => 'array', 'log' => [ 'level' => 'debug', 'file' => app()->getRuntimePath() . 'log/'.date('Ym').'/wechat_debug.log', ], ]); } /** * 显示资源列表 * * @return \think\Response * @throws \Lettered\Support\Exceptions\FailedException * @throws \think\exception\DbException */ public function index() { $where[] = ['area_id', 'eq', $this->auth->user()['area_id']]; $list = $this->model->where($where)->with(['taxi','taxi.user','user','category']) ->order('created_at' , 'desc') ->paginate(input('limit'),false); return IResponse::paginate($list); } /** * 显示创建资源表单页. * * @return \think\Response */ public function create() { // } /** * 保存新建的资源 * * @param \think\Request $request * @return \think\Response */ public function save(Request $request) { // } /** * 显示指定的资源 * * @param int $id * @return \think\Response */ public function read($id) { // } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function edit($id) { // } /** * 保存更新的资源 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function update(Request $request, $id) { // } /** * @desc 指派司机 * @param $id * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException * @throws \think\exception\PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/27 0027 */ public function dispense($id) { $model = model('common/TaxiOrder'); $order = $model->findBy($id); //TODO 应该把当前车俩设置为占用 // 获取用户信息 $user = model('common/Users')->findBy($order['user_id']); $Taxi = new \app\common\model\Taxi(); $driver = $Taxi->with('user')->find($order['taxi_id']); $result = false; $this->model->startTrans(); try { // 订阅消息 $this->wechat->subscribe_message->send([ 'template_id' => 'v2nNL6LKvYr0pyGsTBw5r9Zaa7lS63Hm5AjvJq-tKWc', // 所需下发的订阅模板id 'touser' => $user['open_id'],//'o11PJ5Qs7asNf0KgdOaKjjWTeGpo', // 'page' => '/pages/motor/order/order', 'data' => [ 'character_string1' => [ 'value' => $order['order_no'], ], 'thing5' => [ 'value' => '电话请保持通畅,师傅正在赶往路上,请稍候', ], 'thing11' => [ 'value' => $driver['user']['uname'], ], 'phone_number6' => [ 'value' => $driver['user']['mobile'], ], 'time7' => [ 'value' => date("Y/m/d H:i:s"), ], ] ]); // 状态以及时间 $result = $model->updateBy($id,[ 'status' => 3 ]); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result) { return IResponse::success([],'成功'); } return IResponse::failure('失败'); } /** * @desc 结束服务 * @param $id * @throws \think\exception\PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/27 0027 */ public function complete($id) { $model = model('common/TaxiOrder'); $order = $model->findBy($id); $result = false; $this->model->startTrans(); try { //TODO 应该把当前车俩设置为 空闲 // 已支付订单,标记为已经服务了 $model->updateBy($id,[ 'status' => 4, 'served' => ($order['status'] == 3) ? '1' : '0' ]); $result = true; $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result) { return IResponse::success([],'成功'); } return IResponse::failure('失败'); } /** * 删除指定资源 * * @param int $id * @return \think\Response */ public function delete($id) { model('common/TaxiOrder')->deleteBy($id); return IResponse::success([],'成功'); } }