123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-09-11
- * Time: 11:17
- */
- namespace app\back\controller;
- use app\back\model\AgencyModel;
- use app\back\model\RegionModel;
- use app\back\model\JsModel;
- use app\back\model\JsOrderModel;
- use app\back\model\UserModel;
- use Cassandra\Map;
- use cmf\controller\AdminBaseController;
- use app\back\model\JsProjectModel;
- use JPush\Client;
- use think\Db;
- class JsOrderController extends AdminBaseController
- {
- /**
- * @return mixed
- * 实时订单
- */
- public function index()
- {
- $id = cmf_get_current_admin_id();
- $admin = UserModel::find($id);
- $userObject = UserModel::where('mobile', $admin->user_login)->where('user_type', 2)->select();
- $userArray = $userObject->toArray();
- if (count($userArray)) {
- $user = $userObject[0];
- }
- $agency_id = 0;
- if (isset($user->agency_id) && !empty($user->agency_id)) {
- $agency_id = (int)$user->agency_id;
- }
- $where = [];
- //如果有 代理 id 表示 是有区县代理的
- if ($agency_id) {
- $agency = AgencyModel::find($agency_id);
- //需要判断 renk_id 是 1 还是 2 1级代理是地级市 2级代理是区县级
- if ($agency->renk_id === 1) {
- $region = RegionModel::where('id', $agency->city_id)->select()[0];
- $where['city'] = $region->cityName;
- } else {
- $region = RegionModel::where('id', $agency->district_id)->select()[0];
- $where['district'] = $region->cityName;
- }
- }
- //$where = [];
- $pw = [];
- $where['type'] = 1;
- $page = $this->request->param('page', 1);
- $JsOrderModel = new JsOrderModel();
- $district = $this->request->param('district');
- if ($district) {
- $this->assign('district', $district);
- }
- $project_id = $this->request->param('project_id');
- $keyword = $this->request->param('keyword');
- if ($keyword) {
- $user_ids = UserModel::where('user_nickname|mobile', 'like', '%' . $keyword . '%')->field('id')->select();
- $user_new_ids = [];
- foreach ($user_ids as $vo) {
- $user_new_ids[] = $vo['id'];
- }
- $where['user_id'] = $user_new_ids;
- $this->assign('keyword', $keyword);
- }
- if ($project_id) {
- $where['project_id'] = $project_id;
- $pw['project_id'] = $project_id;
- $this->assign('project_id', $project_id);
- }
- $order_sn = $this->request->param('order_sn');
- if ($order_sn) {
- $this->assign('order_sn', $order_sn);
- $pw['order_sn'] = $order_sn;
- }
- $status = $this->request->param('status', '');
- if ($status !== '') {
- $where['status'] = $status;
- $pw['status'] = $status;
- $this->assign('status', $status);
- }
- $list = $JsOrderModel->getList($where, $page, 'index', $pw, $order_sn, $district);
- if ($agency_id) {
- foreach ($list as $k => $v) {
- $mobile = $v->mobile;
- if ($mobile) {
- $startStr = substr($mobile, 0, 3);
- $endStr = substr($mobile, -3);
- $list[$k]->mobile = $startStr . '*****' . $endStr;
- }
- $xiadan_user = $v->xiadan_user;
- if ($xiadan_user['mobile']) {
- $xiadan_user_mobile = $xiadan_user['mobile'];
- $startStr = substr($xiadan_user_mobile, 0, 3);
- $endStr = substr($xiadan_user_mobile, -3);
- $list[$k]->xiadan_user['mobile'] = $startStr . '*****' . $endStr;
- }
- $js = $v->js;
- if ($js['phone']) {
- $js_phone = $js['phone'];
- $startStr = substr($js_phone, 0, 3);
- $endStr = substr($js_phone, -3);
- $list[$k]->js['phone'] = $startStr . '*****' . $endStr;
- }
- }
- }
- // dump($list->toArray());
- $JsProjectModel = new JsProjectModel();
- $js_project_list = $JsProjectModel::field('id,name')->select();
- // dump($js_project_list->toArray());
- $this->assign('js_project_list', $js_project_list);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- /**
- * @return mixed
- * 预约订单
- */
- public function make()
- {
- $id = cmf_get_current_admin_id();
- $admin = UserModel::find($id);
- $userObject = UserModel::where('mobile', $admin->user_login)->where('user_type', 2)->select();
- $userArray = $userObject->toArray();
- if (count($userArray)) {
- $user = $userObject[0];
- }
- $agency_id = 0;
- if (isset($user->agency_id) && !empty($user->agency_id)) {
- $agency_id = (int)$user->agency_id;
- }
- $where = [];
- //如果有 代理 id 表示 是有区县代理的
- if ($agency_id) {
- $agency = AgencyModel::find($agency_id);
- //需要判断 renk_id 是 1 还是 2 1级代理是地级市 2级代理是区县级
- if ($agency->renk_id === 1) {
- $region = RegionModel::where('id', $agency->city_id)->select()[0];
- $where['city'] = $region->cityName;
- } else {
- $region = RegionModel::where('id', $agency->district_id)->select()[0];
- $where['district'] = $region->cityName;
- }
- }
- //$where = [];
- $pw = [];
- $where['type'] = 2;
- $page = $this->request->param('page', 1);
- $JsOrderModel = new JsOrderModel();
- $project_id = $this->request->param('project_id');
- $keyword = $this->request->param('keyword');
- if ($keyword) {
- $user_ids = UserModel::where('user_nickname|mobile', 'like', '%' . $keyword . '%')->field('id')->select();
- $user_new_ids = [];
- foreach ($user_ids as $vo) {
- $user_new_ids[] = $vo['id'];
- }
- $where['user_id'] = $user_new_ids;
- $this->assign('keyword', $keyword);
- }
- if ($project_id) {
- $where['project_id'] = $project_id;
- $pw['project_id'] = $project_id;
- $this->assign('project_id', $project_id);
- }
- $order_sn = $this->request->param('order_sn');
- if ($order_sn) {
- $this->assign('order_sn', $order_sn);
- $pw['order_sn'] = $order_sn;
- }
- $status = $this->request->param('status', '');
- if ($status !== '') {
- $where['status'] = $status;
- $pw['status'] = $status;
- $this->assign('status', $status);
- }
- $district = $this->request->param('district');
- if ($district) {
- $this->assign('district', $district);
- }
- $list = $JsOrderModel->getList($where, $page, 'index', $pw, $order_sn, $district);
- if ($agency_id) {
- foreach ($list as $k => $v) {
- $mobile = $v->mobile;
- if ($mobile) {
- $startStr = substr($mobile, 0, 3);
- $endStr = substr($mobile, -3);
- $list[$k]->mobile = $startStr . '*****' . $endStr;
- }
- $xiadan_user = $v->xiadan_user;
- if ($xiadan_user['mobile']) {
- $xiadan_user_mobile = $xiadan_user['mobile'];
- $startStr = substr($xiadan_user_mobile, 0, 3);
- $endStr = substr($xiadan_user_mobile, -3);
- $list[$k]->xiadan_user['mobile'] = $startStr . '*****' . $endStr;
- }
- $js = $v->js;
- if ($js['phone']) {
- $js_phone = $js['phone'];
- $startStr = substr($js_phone, 0, 3);
- $endStr = substr($js_phone, -3);
- $list[$k]->js['phone'] = $startStr . '*****' . $endStr;
- }
- }
- }
- $JsProjectModel = new JsProjectModel();
- $js_project_list = $JsProjectModel::field('id,name')->select();
- $this->assign('js_project_list', $js_project_list);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- public function delete()
- {
- $id = $this->request->param('id');
- JsOrderModel::destroy($id);
- $this->success('删除成功');
- }
- /**
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- * 后台完成订单服务
- */
- public function finish()
- {
- $ids = $this->request->param('ids/a');
- $JsOrderModel = new JsOrderModel();
- JsOrderModel::where('id', 'in', $ids)->update(['finish_time' => time(), 'status' => 3]);
- $list = $JsOrderModel::where('id', 'in', $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');
- JsModel::where('id', $vo['jiedan_js_id'])->setInc('jiedan_num', 1);
- if ($vo['order_price'] > 0) {
- 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 getJsList($lat = 1, $lng = 1)
- {
- $url = 'http://116.255.226.95:82/api/js/getList?lng=' . $lng . '&lat=' . $lat;
- $this->assign('list', []);
- return $this->fetch('jslist');
- }
- public function qdlist()
- {
- $id = $this->request->param('id');
- $list = Db::name('js_order_grab')->where('order_id=' . $id)->order('id asc')->select()->toArray();
- if (!empty($list) && is_array($list)) {
- foreach ($list as $key => $val) {
- $js_info = JsModel::get($val['js_id'])->toArray();
- $list[$key]['js_name'] = $js_info['name'];
- $list[$key]['js_mobile'] = $js_info['phone'];
- }
- }
- $this->assign('list', $list);
- return $this->fetch();
- }
- public function fenxiao($order_id, $type)
- {
- $orderInfo = JsOrderModel::get($order_id);
- $userModel = new UserModel();
- if ($type == 1) {
- $log['remark'] = '好友下单';
- $price = $orderInfo['price'];
- $user_info = UserModel::get($orderInfo['user_id']);
- $agency_info = AgencyModel::where(['district_id' => $user_info['district_id'], 'renk_id' => 2])->find();
- $user_agency_id = Db::name('user')->where(function ($query) use ($agency_info){
- $query->where('agency_id',$agency_info['id']);
- $query->whereOr('agency_id','like',$agency_info['id'].',%');
- $query->whereOr('agency_id','like','%,'.$agency_info['id']);
- $query->whereOr('agency_id','like','%,'.$agency_info['id'].',%');
- })->value('id');
- $money = round($price * $agency_info['ratio'] / 100, 2);
- $user_id = $orderInfo['user_id'];
- if ($money > 0 && $user_agency_id) {
- UserModel::where('id', $user_agency_id)->setInc('balance', $money);
- $log['user_id'] = $user_agency_id;
- $log['money'] = $money;
- $log['type'] = 5;
- $log['add_time'] = time();
- $log['obj_id'] = $order_id;
- $log['is_type'] = $type;
- $log['xia_user_id'] = $user_info['id'];
- $log['remark'] = '用户下单,区代提成';
- Db::name('user_money_log')->insert($log);
- }
- $user_parent_id = $userModel::get($user_id)['parent_id'];
- $user_parent_id1 = $userModel::get($user_id)['parent_id1'];
- if ($user_parent_id) {
- $user_parent_info = UserModel::get($user_parent_id);
- $distributorInfo = Db::name('distributor')->where('id', $user_parent_info['distributor_id'])->find();
- $money = $price * $distributorInfo['yi_ratio'] / 100;
- if ($money > 0) {
- UserModel::where('id', $user_parent_id)->setInc('balance', $money);
- $log['user_id'] = $user_parent_id;
- $log['money'] = $money;
- $log['type'] = 3;
- $log['add_time'] = time();
- $log['obj_id'] = $order_id;
- $log['is_type'] = $type;
- $log['xia_user_id'] = $user_id;
- $log['remark'] = '一级好友下单提成';
- Db::name('user_money_log')->insert($log);
- }
- }
- if ($user_parent_id1) {
- $user_parent_info1 = UserModel::get($user_parent_id1);
- $distributorInfo1 = Db::name('distributor')->where('id', $user_parent_info1['distributor_id'])->find();
- $money = $price * $distributorInfo1['er_ratio'] / 100;
- if ($money > 0) {
- UserModel::where('id', $user_parent_id1)->setInc('balance', $money);
- $log['user_id'] = $user_parent_id1;
- $log['money'] = $money;
- $log['type'] = 4;
- $log['add_time'] = time();
- $log['obj_id'] = $order_id;
- $log['xia_user_id'] = $user_id;
- $log['is_type'] = $type;
- $log['remark'] = '二级好友下单提成';
- Db::name('user_money_log')->insert($log);
- }
- }
- } else {
- if (!$orderInfo['jiedan_js_id']) {
- return false;
- }
- $user_id = Db::name('js')->where('id', $orderInfo['jiedan_js_id'])->value('user_id');
- $log['remark'] = '好友接单';
- $price = $orderInfo['order_price'];
- $user_parent_id = $userModel::get($user_id)['parent_id'];
- $user_parent_id1 = $userModel::get($user_id)['parent_id1'];
- // if($user_parent_id){
- // $user_parent_info = UserModel::get($user_parent_id);
- // $distributorInfo = Db::name('distributor')->where('id',$user_parent_info['distributor_id'])->find();
- // $money = $price * $distributorInfo['yi_ratio']/100;
- // if($money > 0){
- // $log['user_id'] = $user_parent_id;
- // $log['money'] = $money;
- // $log['type'] = 3;
- // $log['add_time'] = time();
- // $log['obj_id'] = $order_id;
- // $log['is_type'] = $type;
- // $log['xia_user_id'] = $user_id;
- // Db::name('user_money_log')->insert($log);
- // }
- // }
- // if($user_parent_id1){
- // $user_parent_info1 = UserModel::get($user_parent_id1);
- // $distributorInfo1 = Db::name('distributor')->where('id',$user_parent_info1['distributor_id'])->find();
- // $money = $price * $distributorInfo1['er_ratio']/100;
- // if($money > 0){
- // $log['user_id'] = $user_parent_id1;
- // $log['money'] = $money;
- // $log['type'] = 4;
- // $log['add_time'] = time();
- // $log['obj_id'] = $order_id;
- // $log['xia_user_id'] = $user_id;
- // $log['is_type'] = $type;
- // Db::name('user_money_log')->insert($log);
- // }
- // }
- }
- }
- }
|