123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-09-07
- * Time: 17:31
- */
- namespace api\js\controller;
- use Aliyun\DySDKLite\SignatureHelper;
- use api\js\model\JsModel;
- use api\js\model\JsOrderGrabModel;
- use api\js\model\JsOrderModel;
- use api\js\model\JsProjectModel;
- use api\js\model\JsScoreModel;
- use api\js\model\JsTimeModel;
- use api\js\model\PortalPostModel;
- use api\js\model\UserDiscountModel;
- use api\js\model\UserModel;
- use Cassandra\Date;
- use cmf\controller\RestUserBaseController;
- use JPush\Client;
- use JPush\Exceptions\APIConnectionException;
- use think\Db;
- use think\facade\Log;
- class JsOrderController extends RestUserBaseController
- {
- /**
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- * 呼叫服务前的信息加载
- */
- public function getUserInfo()
- {
- $user_id = $this->getUserId();
- $UserModel = new UserModel();
- $projectId = $this->request->param('project_id');
- $storeId = $this->request->param('store_id');
- $district = $this->request->param('district');
- if (!$district) {
- $this->error('获取地址失败!');
- }
- $where['user_id'] = $user_id;
- $where['status'] = 0;
- $UserDiscountModel = new UserDiscountModel();
- $UserDiscountModel::where(function ($query) use ($user_id) {
- $query->where('user_id', $user_id);
- $query->where('status', 0);
- $query->where('past_time', '<', time());
- })->update(['status' => 2]);
- $userInfo = $UserModel::where('id', $user_id)->field('mobile,balance')->find();
- $userInfo['discount_count'] = $UserDiscountModel::where($where)->where(function ($query) use ($projectId) {
- if ($projectId) {
- $query->where('project_id', $projectId);
- $query->whereOR('project_id', 0);
- } else {
- $query->where('project_id', 0);
- }
- })->where(function ($query) use ($storeId) {
- if ($storeId) {
- $query->where('store_id', $storeId);
- $query->whereOR('store_id', 0);
- } else {
- $query->where('store_id', 0);
- }
- })->count();
- $userInfo['discount_info'] = [];
- $userDiscountInfo = $UserDiscountModel::with('jsDiscount')->where($where)->where(function ($query) use ($projectId) {
- if ($projectId) {
- $query->where('project_id', $projectId);
- $query->whereOR('project_id', 0);
- } else {
- $query->where('project_id', 0);
- }
- })->where(function ($query) use ($storeId) {
- if ($storeId) {
- $query->where('store_id', $storeId);
- $query->whereOR('store_id', 0);
- } else {
- $query->where('store_id', 0);
- }
- })->find();
- if ($userDiscountInfo) {
- $userInfo['discount_info'] = $userDiscountInfo;
- }
- $JsProjectModel = new JsProjectModel();
- $projectInfo = $JsProjectModel->getInfo($projectId, $district);
- $this->success('ok', ['user_info' => $userInfo, 'project_info' => $projectInfo]);
- }
- /**
- * @throws \think\Exception
- * 创建订单,并余额直接支付
- */
- public function addPost()
- {
- $data['user_id'] = $this->getUserId();
- $badness_num = UserModel::get($data['user_id'])['badness_num'];
- $user_nickname = UserModel::get($data['user_id'])['user_nickname'];
- $info = cmf_get_option('duration');
- if ($badness_num > $info['badness_num']) {
- $this->error('您有不良行为,不可下单!');
- }
- $data['user_discount_id'] = $this->request->param('user_discount_id');
- $data['service_id'] = $this->request->param('service_id');
- if (!$data['service_id']) {
- $this->error('服务区数据异常!');
- }
- $data['project_id'] = $this->request->param('project_id');
- $info = Db::name('js_project_service_relevancy')->where(['project_id' => $data['project_id'], 'id' => $data['service_id']])->find();
- if (!$info) {
- $this->error('该区未开通服务,不可下单!');
- }
- $data['price'] = $info['price'];
- $data['minute'] = $info['minute'];
- $data['order_price'] = $info['order_price'];
- $data['mobile'] = $this->request->param('mobile');
- if (!cmf_check_mobile($data['mobile'])) {
- $this->error('联系方式,手机号格式错误!');
- }
- $data['type'] = $this->request->param('type');
- $appoint_time = $this->request->param('appoint_time');
- if (!empty($appoint_time)) {
- $data['appoint_time'] = strtotime($appoint_time);
- }
- $data['province'] = $this->request->param('province');
- $data['city'] = $this->request->param('city');
- $data['district'] = $this->request->param('district');
- $data['address'] = $this->request->param('address');
- $data['address1'] = $this->request->param('address1');
- // $url = 'https://restapi.amap.com/v3/geocode/geo?key=3c813127122a372b7b0a6f0db7eb911e&address='. $data['province'].$data['city'].$data['district'].$data['address'].'&city='.$data['city'];
- // $res = curl_post_ssl1($url,'');
- // $result = json_decode($res,true);
- // if($result['status'] == 0){
- // $this->error('地址有误!');
- // }
- // $lng_lat = $result['geocodes'][0]['location'];
- // $lng = explode(',',$lng_lat)[0];
- // $lat = explode(',',$lng_lat)[1];
- $data['remark'] = $this->request->param('remark');
- $data['jiedan_js_id'] = $this->request->param('jiedan_user_id');
- $data['lat'] = $this->request->param('lat');
- $data['lng'] = $this->request->param('lng');
- $is_balance = $this->request->param('is_balance');
- $data['order_sn'] = cmf_get_order_sn() . $this->getUserId();
- $data['order_sole'] = md5(uniqid()) . md5(uniqid());
- $voucher = 0;
- if ($data['type'] == 1 && $data['jiedan_js_id']) {
- $week = date('w', time());
- $jsTime = JsTimeModel::where('js_id', $data['jiedan_js_id'])->find();
- $shangban = 0;
- if (in_array($week, $jsTime->weeks)) {
- foreach ($jsTime->times as $vo) {
- if (strtotime($vo['js_end_time']) > strtotime(date('H:i'))) {
- $shangban = 1;
- }
- // dump($vo['js_end_time']);
- }
- }
- if (!$shangban) {
- $this->error('技师休息中,不可下单');
- }
- }
- // 加钟类型
- if ($data['type'] == 3 && $data['jiedan_js_id']) {
- $data['jiedan_time'] = time();
- // 加钟技师佣金
- $data['order_price'] = round($info['price'] * 70 / 100, 2);
- }
- if ($data['user_discount_id']) {
- $userDiscountInfo = Db::name('user_discount')->where('id', $data['user_discount_id'])->find();
- if ($userDiscountInfo['past_time'] < time()) {
- $this->error('优惠券已过期!');
- }
- if ($userDiscountInfo['project_id'] != 0) {
- if ($userDiscountInfo['project_id'] != $data['project_id']) {
- $this->error('优惠券不适用该项目!');
- }
- }
- $voucher = Db::name('js_discount')->where('id', $userDiscountInfo['discount_id'])->value('voucher');
- }
- $data['voucher_price'] = $voucher;
- if ($voucher > $data['price']) {
- $this->error('优惠券不适用该项目!');
- }
- $data['pay_price'] = $data['price'] - $voucher;
- $JsOrderModel = new JsOrderModel();
- if ($is_balance == 1) {
- $userDalance = UserModel::get($this->getUserId())['balance'];
- if ($userDalance >= $data['pay_price']) {
- UserModel::where('id', $this->getUserId())->setDec('balance', $data['pay_price']);
- $data['status'] = 1;
- $data['pay_time'] = time();
- $data['pay_type'] = '余额支付';
- $JsOrderModel->allowField(true)->isUpdate(false)->save($data);
- $orderId = $JsOrderModel->id;
- $erweiam = qeCode($data['order_sole'], $this->request->controller(), $orderId);
- $JsOrderModel->allowField(true)->isUpdate(true)->save(['erweima' => $erweiam], ['id' => $orderId]);
- $log['user_id'] = $this->getUserId();
- $log['money'] = -$data['pay_price'];
- $log['order_sn'] = $data['order_sn'];
- $log['yue'] = $userDalance - $data['pay_price'];
- $log['type'] = 1;
- $log['remark'] = '呼叫服务余额支付';
- $log['add_time'] = time();
- $log['obj_id'] = $orderId;
- if ($log['money'] != 0) {
- Db::name('user_money_log')->insert($log);
- }
- Db::name('js_project')->where('id', $data['project_id'])->setInc('sales_num', 1);
- Db::name('user_discount')->where('id', $data['user_discount_id'])->update(['hours_time' => time(), 'status' => 1]);
- if ($data['jiedan_js_id']) {
- $helper = new SignatureHelper();
- $alisms = cmf_get_option('alisms');
- $security = false;
- $accessKeyId = $alisms['access_key_id'];
- $accessKeySecret = $alisms['access_key_secret'];
- $js_mobile = UserModel::get(JsModel::get($data['jiedan_js_id'])['user_id'])['mobile'];
- $params["PhoneNumbers"] = $js_mobile;
- $params["SignName"] = '嘀咚点到';
- if ($data['type'] == 1) {
- $params["TemplateCode"] = 'SMS_204986367';
- $params['TemplateParam'] = array(
- "product" => JsProjectModel::get($data['project_id'])['name'],
- );
- } else if ($data['type'] == 2) {
- $params["TemplateCode"] = 'SMS_204986363';
- $params['TemplateParam'] = array(
- "time" => $appoint_time,
- );
- }
- if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
- $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
- }
- $content = $helper->request(
- $accessKeyId,
- $accessKeySecret,
- "dysmsapi.aliyuncs.com",
- array_merge($params, array(
- "RegionId" => "cn-hangzhou",
- "Action" => "SendSms",
- "Version" => "2017-05-25",
- )),
- $security
- );
- }
- $this->success('支付成功', $JsOrderModel->id);
- } else {
- $this->error('余额不足');
- }
- } else {
- $JsOrderModel->allowField(true)->isUpdate(false)->save($data);
- $orderId = $JsOrderModel->id;
- $erweiam = qeCode($data['order_sole'], $this->request->controller(), $orderId);
- $JsOrderModel->allowField(true)->isUpdate(true)->save(['erweima' => $erweiam], ['id' => $orderId]);
- $this->success('创建订单成功', $JsOrderModel->id);
- }
- }
- /**
- * 用户结束服务
- */
- public function finish()
- {
- $ids = $this->request->param('order_id');
- if (empty($ids)) {
- $this->error('请选择要结束的订单');
- exit();
- }
- $JsOrderModel = new \app\back\model\JsOrderModel();
- JsOrderModel::where('id', $ids)->update(['finish_time' => time(), 'status' => 3]);
- $list = $JsOrderModel::where('id', $ids)->field('id,user_id,jiedan_js_id,order_price')->select();
- $info = cmf_get_option('jspus');
- foreach ($list as $vo) {
- $url = '/pages/ddxq/ddxq?id=' . $vo['id'];
- $jsuserid = $js_user_id = Db::name('js')->where('id', $vo['jiedan_js_id'])->value('user_id');
- \app\back\model\JsModel::where('id', $vo['jiedan_js_id'])->setInc('jiedan_num', 1);
- if ($vo['order_price'] > 0) {
- \app\back\model\UserModel::where('id', $jsuserid)->setInc('balance', $vo['order_price']);
- $log['user_id'] = $jsuserid;
- $log['money'] = $vo['order_price'];
- $log['type'] = 8;
- $log['remark'] = '完成服务获得金额';
- $log['add_time'] = time();
- $log['obj_id'] = $vo['id'];
- if ($log['money'] != 0) {
- Db::name('user_money_log')->insert($log);
- }
- }
- $js_user_id .= 'js';
- $js_client = new Client($info['js_app_key'], $info['js_master_secret']);
- $client = new Client($info['app_key'], $info['master_secret']);
- $extras = [
- 'id' => $vo['id'],
- 'flag' => '用户',
- 'url' => $url
- ];
- $array = [
- 'extras' => $extras,
- ];
- $text = '服务已被您指定结束';
- $platform = array('ios', 'android');
- $user_id = $vo['user_id'] . 'js';
- $client->push()
- ->setPlatform($platform)
- ->setNotificationAlert($text)
- ->iosNotification($text, $array)
- ->androidNotification($text, $array)
- ->addAlias("{$user_id}")
- ->send();
- $extras = [
- 'id' => $vo['id'],
- 'flag' => '技师端',
- 'url' => $url
- ];
- $array = [
- 'extras' => $extras,
- ];
- $text = '服务已被用户指定结束';
- $js_client->push()
- ->setPlatform($platform)
- ->setNotificationAlert($text)
- ->iosNotification($text, $array)
- ->androidNotification($text, $array)
- ->addAlias("{$js_user_id}")
- ->send();
- $this->fenxiao($vo['id'], 1);
- $this->fenxiao($vo['id'], 2);
- }
- $this->success('操作成功');
- }
- /**
- * 其他方式支付订单
- */
- public function pay()
- {
- $id = $this->request->param('order_id');
- $pay_type = $this->request->param('pay_type');
- switch ($pay_type) {
- case 'wxpay':
- $res = wx_pay($id, 3);
- if (!empty($res['return_code']) && $res['return_code'] == 'FAIL') {
- $this->error($res['return_msg']);
- } else {
- $this->success('ok', $res);
- }
- break;
- case 'alipay':
- $res = aly_pay($id, 3);
- if (!empty($res['return_code'])) {
- $this->error($res['return_msg']);
- } else {
- $this->success('ok', $res);
- }
- break;
- case 'balance':
- $orderInfo = JsOrderModel::get($id);
- $userDalance = UserModel::get($this->getUserId())['balance'];
- if ($orderInfo['status'] != 0) {
- $this->error('订单已支付!');
- }
- if ($userDalance >= $orderInfo['pay_price']) {
- $res = UserModel::where('id', $this->getUserId())->setDec('balance', $orderInfo['pay_price']);
- if ($res) {
- $data['status'] = 1;
- $data['pay_time'] = time();
- $data['pay_type'] = '余额支付';
- JsOrderModel::where('id', $id)->update($data);
- $orderId = $id;
- $log['user_id'] = $orderInfo['user_id'];
- $log['money'] = -$orderInfo['pay_price'];
- $log['yue'] = $userDalance - $orderInfo['pay_price'];
- $log['order_sn'] = $orderInfo['order_sn'];
- $log['type'] = 1;
- $log['remark'] = '呼叫服务余额支付';
- $log['add_time'] = time();
- $log['obj_id'] = $orderId;
- Db::name('user_money_log')->insert($log);
- Db::name('js_project')->where('id', $orderInfo['project_id'])->setInc('sales_num', 1);
- Db::name('user_discount')->where('id', $orderInfo['user_discount_id'])->update(['hours_time' => time(), 'status' => 1]);
- $this->success('支付成功', $orderId);
- }
- $this->error('余额支付失败,请重新支付');
- } else {
- $this->error('余额不足');
- }
- break;
- }
- }
- /**
- * 我的订单
- */
- public function getList()
- {
- $where = [];
- $JsOrderModel = new JsOrderModel();
- $status = $this->request->param('status');
- $project_name = $this->request->param('project_name');
- $user_id = $this->getUserId();
- $where['user_id'] = $user_id;
- if ($status || $status === '0') {
- if ($status == '9') $where['status'] = array('1', '2', '6');
- else $where['status'] = $status;
- }
- $where['user_delete'] = 1;
- $page = $this->request->param('page');
- $list = $JsOrderModel->getList($where, $page, $project_name, $status);
- $this->success('ok', $list);
- }
- /**
- * 获取抢单订单
- */
- public function getSeizeOrder()
- {
- $JsOrderModel = new JsOrderModel();
- $user_id = $this->getUserId();
- $where = ['user_id' => $user_id, 'status' => 1, 'jiedan_js_id' => 0];
- $list = $JsOrderModel->where($where)->select();
- $count = count($list->toArray());
- $fast_number = 0;
- foreach ($list as $vo) {
- $fast_number += $vo['fast_number'];
- }
- $this->success('获取成功', ['count' => $count, 'fast_number' => $fast_number]);
- }
- /**
- * 订单取消
- */
- public function orderCancel()
- {
- $id = $this->request->param('order_id');
- $JsOrderModel = new JsOrderModel();
- $log_file = './fencheng/cancel_' . date("YmdH") . '.txt';
- $orderInfo = $JsOrderModel::get($id);
- // if($orderInfo['status'] != 0 && $orderInfo['status'] != 1){
- // $this->error('该状态订单不可取消!');
- // }
- $timestamp = time();
- $waitTime = 15;
- $userDalance = UserModel::get($orderInfo['user_id'])['balance'];
- if ($orderInfo['status'] == '0') {
- JsOrderModel::destroy($id);
- } else if ($orderInfo['status'] == '1') {
- // 支付订单 15分钟内禁止取消订单
- // if ($timestamp - $orderInfo['pay_time'] < $waitTime * 60) {
- // $this->error("订单支付成功后,需等待 {$waitTime} 分钟才可取消订单!");
- // }
- $outMoney = $orderInfo['pay_price'];
- UserModel::where('id', $orderInfo['user_id'])->setInc('balance', $outMoney);
- $log['user_id'] = $orderInfo['user_id'];
- $log['money'] = $outMoney;
- $log['order_sn'] = $orderInfo['order_sn'];
- $log['yue'] = $outMoney + $userDalance;
- $log['type'] = 2;
- $log['remark'] = '取消服务支付金额退还到余额';
- $log['add_time'] = time();
- $log['obj_id'] = $id;
- Db::name('user_money_log')->insert($log);
- $JsOrderModel::where('id', $id)->update(['status' => 5]);
- } else if ($orderInfo['status'] == 2) {
- $withhold = Db::name('withhold')->where('id', 1)->find();
- if (time() - $orderInfo['jiedan_time'] > 30 * 60) {
- $withhold = Db::name('withhold')->where('id', 3)->find();
- } elseif (time() - $orderInfo['jiedan_time'] < 30 * 60 && time() - $orderInfo['jiedan_time'] > 15 * 60) {
- $withhold = Db::name('withhold')->where('id', 2)->find();
- }
- $refund_money = round($orderInfo['pay_price'] * ($withhold['deduct'] / 100), 2);
- $deserved_money = $orderInfo['pay_price'] - $refund_money;
- $refund_money = $refund_money - round(($orderInfo['pay_price'] * ($withhold['terrace'] / 100)), 2);
- $JsOrderModel::where('id', $id)->update(['status' => 5, 'return_time' => time()]);
- UserModel::where('id', $orderInfo['user_id'])->setInc('balance', $deserved_money);
- $log['user_id'] = $orderInfo['user_id'];
- $log['money'] = $deserved_money;
- $log['yue'] = $deserved_money + $userDalance;
- $log['order_sn'] = $orderInfo['order_sn'];
- $log['type'] = 2;
- $log['remark'] = '取消服务支付金额退还到余额';
- $log['add_time'] = time();
- $log['obj_id'] = $id;
- Db::name('user_money_log')->insert($log);
- if ($refund_money > 0) {
- $user_id = JsModel::get($orderInfo['jiedan_js_id'])['user_id'];
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'user_id.......' . $user_id . "\n", FILE_APPEND);
- $userDalance = UserModel::get($user_id)['balance'];
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'userDalance......' . $userDalance . "\n", FILE_APPEND);
- UserModel::where('id', $user_id)->setInc('balance', $refund_money);
- $log1['user_id'] = $user_id;
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'user_id......' . $log1['user_id'] . "\n", FILE_APPEND);
- $log1['money'] = $refund_money;
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'money......' . $log1['money'] . "\n", FILE_APPEND);
- $log1['yue'] = $refund_money + $userDalance;
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'yue......' . $log1['yue'] . "\n", FILE_APPEND);
- $log1['order_sn'] = $orderInfo['order_sn'];
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'order_sn......' . $log1['order_sn'] . "\n", FILE_APPEND);
- $log1['type'] = 6;
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'type......' . $log1['type'] . "\n", FILE_APPEND);
- $log1['remark'] = '用户取消订单,接单补偿金额';
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'remark......' . $log1['remark'] . "\n", FILE_APPEND);
- $log1['add_time'] = time();
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'add_time......' . $log1['add_time'] . "\n", FILE_APPEND);
- $log1['obj_id'] = $id;
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'obj_id......' . $log1['obj_id'] . "\n", FILE_APPEND);
- $log1['order_id'] = $id;
- @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'order_id......' . $log1['order_id'] . "\n", FILE_APPEND);
- Db::name('user_money_log')->insert($log1);
- }
- }
- $JsOrderModel->allowField(true)->isUpdate(true)->save(['order_status' => 2], ['id' => $id]);
- $this->success('取消成功');
- }
- /**
- * 评价操作
- */
- public function setJsScore()
- {
- $id = $this->request->param('order_id');
- // $score = $this->request->param('score');
- $content = $this->request->param('content');
- $times = $this->request->param('times');
- $manner = $this->request->param('manner');
- $jishu = $this->request->param('jishu');
- $JsOrderModel = new JsOrderModel();
- $jiedan_js_id = $JsOrderModel::get($id)['jiedan_js_id'];
- $project_id = $JsOrderModel::get($id)['project_id'];
- // $js_id = JsModel::where('user_id',$jiedan_user_id)->value('id');
- $data['user_id'] = $this->getUserId();
- $data['order_id'] = $id;
- $data['js_id'] = $jiedan_js_id;
- $data['project_id'] = $project_id;
- $data['score'] = ceil(($times + $manner + $jishu) / 3);
- $data['content'] = $content;
- $data['times'] = $times;
- $data['manner'] = $manner;
- $data['jishu'] = $jishu;
- $JsScoreModel = new JsScoreModel();
- $JsScoreModel->allowField(true)->isUpdate(false)->save($data);
- $JsOrderModel::where('id', $id)->update(['status' => 4]);
- $this->success('评价成功');
- }
- /**
- * 订单详情
- */
- public function getInfo()
- {
- $id = $this->request->param('order_id');
- $order_no = $this->request->param('order_no');
- $call_id = $this->request->param('call_id');
- if ($call_id) {
- $info = Db::name('js_call')->where('id', $call_id)->find();
- if (!$info['agency_is_look']) {
- Db::name('js_call')->where('id', $call_id)->update(['agency_is_look' => 1, 'agency_is_look_time' => time()]);
- } else {
- if ((time() - $info['agency_is_look_time']) > 3600) {
- $this->error('信息不可查看!');
- }
- }
- }
- $JsOrderModel = new JsOrderModel();
- if (!$id && $order_no) {
- $id = $JsOrderModel::where('order_sn', $order_no)->value('id');
- }
- $orderInfo = $JsOrderModel::get($id, ['project', 'js', 'addtime' => function ($qyery) {
- $qyery->where(['status' => 1]);
- }]);
- $user_type = UserModel::get($this->userId)['user_type'];
- $orderInfo->distance = 0;
- if ($orderInfo['jiedan_js_id']) {
- $js_site_info = Db::name('js_site')->where('js_id', $orderInfo['jiedan_js_id'])->find();
- if ($js_site_info['lat'] && $js_site_info['lng'] && $orderInfo['lat'] && $orderInfo['lng']) {
- $orderInfo->distance = GetDistance($js_site_info['lat'], $js_site_info['lng'], $orderInfo['lat'], $orderInfo['lng'], 2, 2);
- } else {
- $orderInfo->distance = 0;
- }
- }
- if ($orderInfo->status == 5 || $orderInfo->status == 7 || $orderInfo->status < 2) {
- $orderInfo->mobile = substr_replace($orderInfo->mobile, '****', 3, 4);
- }
- if ($user_type == 3) {
- $js_id = JsModel::where('user_id', $this->userId)->value('id');
- $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
- if ($js_site_info['lat'] && $js_site_info['lng'] && $orderInfo['lat'] && $orderInfo['lng']) {
- $orderInfo->distance = GetDistance($js_site_info['lat'], $js_site_info['lng'], $orderInfo['lat'], $orderInfo['lng'], 2, 2);
- } else {
- $orderInfo->distance = 0;
- }
- }
- $service = ['project_id' => $orderInfo['project_id'], 'minute' => $orderInfo['minute'], 'price' => $orderInfo['pay_price']];
- $orderInfo->project_service = $service;
- $orderInfo = $orderInfo->toarray();
- if ($orderInfo['status'] == 5 || $orderInfo['status'] == 7 || $orderInfo['status'] < 2) {
- $orderInfo['js']['phone'] = substr_replace($orderInfo['js']['phone'], '****', 3, 4);
- }
- // $orderInfo->project_service = Db::name('js_project_service_relevancy')->where('id',$orderInfo['service_id'])->find();
- $this->success('ok', $orderInfo);
- }
- /**
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * 获取抢单技师列表
- */
- public function selectJs()
- {
- $order_id = $this->request->param('order_id');
- if (!$order_id) {
- $this->error('缺少order_id参数');
- }
- $JsOrderGrab = new JsOrderGrabModel();
- $order_info = JsOrderModel::get($order_id);
- if (!$order_info) {
- $this->error('订单不存在!');
- }
- $list = $JsOrderGrab::with('js.site')->where('order_id', $order_id)->select();
- foreach ($list as $key => $value) {
- if ($list[$key]->js) {
- $list[$key]->js->score = get_js_score($list[$key]->js_id);
- }
- if ($value->js->site) {
- $list[$key]->distance = GetDistance($order_info['lat'], $order_info['lng'], $value->js->site->lat, $value->js->site->lng, 2, 2);
- } else {
- $list[$key]->distance = '距离不详';
- }
- }
- $paixu = 'asc';
- $len = count($list);
- for ($i = 1; $i < $len; $i++) {
- for ($k = 0; $k < $len - $i; $k++) {
- if ($paixu == 'asc' || $paixu == '') {
- if ($list[$k]['distance'] > $list[$k + 1]['distance']) {
- $array = $list[$k + 1];
- $list[$k + 1] = $list[$k];
- $list[$k] = $array;
- }
- } else {
- if ($list[$k]['distance'] < $list[$k + 1]['distance']) {
- $array = $list[$k + 1];
- $list[$k + 1] = $list[$k];
- $list[$k] = $array;
- }
- }
- }
- }
- $this->success('ok', $list);
- }
- /**
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- * 用户选择技师操作
- */
- public function doSelectJs()
- {
- $order_id = $this->request->param('order_id');
- $js_id = $this->request->param('js_id');
- if (!$order_id) {
- $this->error('缺少order_id参数');
- }
- if (!$js_id) {
- $this->error('缺少js_id参数');
- }
- $JsOrderModel = new JsOrderModel();
- $order_info = JsOrderModel::get($order_id);
- if (!$order_info) {
- $this->error('订单不存在!');
- }
- $msg = '订单未支付!';
- switch ($order_info['status']) {
- case 2:
- $msg = '技师已选择!';
- break;
- case 6:
- $msg = '服务中!';
- break;
- case 3:
- $msg = '订单已完成!';
- break;
- case 4:
- $msg = '订单已评价!';
- break;
- case 5:
- $msg = '订单已取消!';
- break;
- }
- $order_id_new = $JsOrderModel::where(function ($query) {
- $query->whereOR('status', 2);
- $query->whereOR('status', 6);
- })->where('jiedan_js_id', $js_id)->value('id');
- if ($order_id_new) {
- $this->error('技师被选走了!');
- }
- if ($order_info['status'] != 1) {
- $this->error($msg);
- } else {
- $JsOrderModel->allowField(true)->isUpdate(true)->save(['jiedan_js_id' => $js_id, 'jiedan_time' => time(), 'status' => 2], ['id' => $order_id]);
- $JsOrderGrabModel = new JsOrderGrabModel();
- $JsOrderGrabModel->allowField(true)->isUpdate(true)->save(['status' => 1], ['order_id' => $order_id, 'js_id' => $js_id]);
- JsOrderGrabModel::where(['order_id' => $order_id, 'status' => 0])->delete();
- $info = cmf_get_option('jspus');
- $url = '/pages/ddxq/ddxq?id=' . $order_id;
- $js_client = new Client($info['js_app_key'], $info['js_master_secret']);
- $js_user_id = Db::name('js')->where('id', $js_id)->value('user_id');
- $js_user_id .= 'js';
- $extras = [
- 'id' => $order_id,
- 'flag' => '技师端',
- 'url' => $url
- ];
- $array = [
- 'extras' => $extras,
- ];
- $text = '您有新的服务订单,请及时处理!';
- $platform = array('ios', 'android');
- try {
- $js_client->push()
- ->setPlatform($platform)
- ->setNotificationAlert($text)
- ->iosNotification($text, $array)
- ->androidNotification($text, $array)
- ->addAlias("{$js_user_id}")
- ->send();
- $this->success('选择成功');
- } catch (\JPush\Exceptions\APIConnectionException $e) {
- $this->success('选择成功');
- } catch (\JPush\Exceptions\APIConnectionException $e) {
- $this->success('选择成功');
- }
- }
- }
- /**
- * 用户删除i订单
- */
- public function deleteOrder()
- {
- $order_id = $this->request->param('order_id');
- $JsOrderModel = new JsOrderModel();
- $JsOrderModel::where('id', $order_id)->update(['user_delete' => 2]);
- $this->success('删除成功');
- }
- /**
- * 扣款规则
- */
- public function getwithhold()
- {
- $list = Db::name('withhold')->select();
- $this->success('ok', $list);
- }
- /**
- * 加钟
- * 服务加时
- */
- public function addTime()
- {
- $order_id = $this->request->param('order_id');
- $pay_type = $this->request->param('pay_type');
- $info = JsOrderModel::get($order_id);
- $serve_info = Db::name('js_project_service_relevancy')->where('id', $info['service_id'])->find();
- if (!$serve_info) {
- $this->error('订单服务数据不存在了!');
- }
- if ($info['status'] != 6) {
- $this->error('订单不在服务中,不可加钟');
- }
- $data['pay_price'] = $serve_info['price'];
- $data['order_id'] = $info['id'];
- $data['order_sn'] = cmf_get_order_sn();
- $data['order_price'] = $serve_info['order_price'];
- $data['service_time'] = $serve_info['minute'];
- switch ($pay_type) {
- case 'wxpay':
- $order_addtime_id = Db::name('js_order_addtime')->insertGetId($data);
- if ($order_addtime_id) {
- $res = wx_pay($order_addtime_id, 100);
- if (!empty($res['return_code'])) {
- $this->error($res['return_msg']);
- } else {
- $this->success('ok', $res);
- }
- } else {
- $this->error('加钟失败!');
- }
- break;
- case 'alipay':
- $order_addtime_id = Db::name('js_order_addtime')->insertGetId($data);
- if ($order_addtime_id) {
- $res = aly_pay($order_addtime_id, 100);
- if (!empty($res['return_code'])) {
- $this->error($res['return_msg']);
- } else {
- $this->success('ok', $res);
- }
- } else {
- $this->error('加钟失败!');
- }
- case 'balance':
- $userDalance = UserModel::get($this->getUserId())['balance'];
- if ($userDalance >= $data['pay_price']) {
- UserModel::where('id', $this->getUserId())->setDec('balance', $data['pay_price']);
- $data['pay_time'] = time();
- $data['pay_type'] = '余额支付';
- $data['status'] = 1;
- $order_data['price'] = $data['pay_price'] + $info['price'];
- $order_data['pay_price'] = $data['pay_price'] + $info['price'];
- $order_data['minute'] = $data['service_time'] + $info['minute'];
- $order_data['order_price'] = $data['order_price'] + $info['order_price'];
- $JsOrderModel = new JsOrderModel();
- $JsOrderModel->allowField(true)->isUpdate(true)->save($order_data, ['id' => $order_id]);
- $orderId = $order_id;
- $log['user_id'] = $info['user_id'];
- $log['money'] = -$data['pay_price'];
- $log['yue'] = $userDalance - $data['pay_price'];
- $log['order_sn'] = $data['order_sn'];
- $log['type'] = 7;
- $log['remark'] = '加钟余额支付';
- $log['add_time'] = time();
- $log['obj_id'] = $orderId;
- Db::name('user_money_log')->insert($log);
- Db::name('js_project')->where('id', $info['project_id'])->setInc('sales_num', 1);
- Db::name('js_order_addtime')->insertGetId($data);
- // Db::name('')
- $this->success('加钟成功', $orderId);
- } else {
- $this->error('余额不足');
- }
- break;
- }
- }
- }
|