| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- namespace app\agent\controller\order;
- use app\common\controller\AgentController;
- use app\http\IResponse;
- use EasyWeChat\Factory;
- use Lettered\Support\Auth as IAuth;
- use think\App;
- use think\Exception;
- use think\Request;
- class Taxi extends AgentController
- {
- protected $model;
- protected $wechat;
- /**
- * Skill constructor.
- * @param App|null $app
- * @param IAuth $auth
- */
- public function __construct(App $app = null, IAuth $auth)
- {
- parent::__construct($app, $auth);
- $this->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([],'成功');
- }
- }
|