Common.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\agent\model\auth\Permission;
  4. use app\api\controller\ApiController;
  5. use app\api\model\user\MotorAgent;
  6. use app\common\model\China;
  7. use think\Exception;
  8. class Common extends ApiController
  9. {
  10. /**
  11. * @desc 摩的代理电话
  12. * @return \think\response\Json
  13. * @throws \think\db\exception\DataNotFoundException
  14. * @throws \think\db\exception\ModelNotFoundException
  15. * @throws \think\exception\DbException
  16. * @author weichuanbao<654745815@qq.com>
  17. * @date 2021/12/22 0022
  18. */
  19. public function motorAgentPhone()
  20. {
  21. $params = input();
  22. $China = new China();
  23. $MotorAgent = new MotorAgent();
  24. $area = $China->field('id,name')
  25. ->where('name', $params['district'])
  26. ->find();
  27. if (!$area) {
  28. return $this->ApiJson(-1,'失败');
  29. }
  30. $row = $MotorAgent->field('id,mobile')
  31. ->where('area_id', $area['id'])
  32. ->find();
  33. if ($row) {
  34. return $this->ApiJson(0,'成功', $row);
  35. }
  36. return $this->ApiJson(-1,'失败');
  37. }
  38. public function demo()
  39. {
  40. $Permission = new Permission();
  41. $list = $Permission->whereNotLike('url', '#%')
  42. ->where('url', '<>', 'javascript:;')
  43. ->where('type', 1)
  44. ->selectOrFail();
  45. $result = false;
  46. $Permission->startTrans();
  47. try {
  48. $data = [];
  49. foreach ($list as $item) {
  50. if (strstr($item['url'], '/agent')) {
  51. $item->url = str_replace('/agent', '', $item['url']);
  52. $loop = $item->getChangedData();
  53. $loop['id'] = $item['id'];
  54. $data[] = $loop;
  55. }
  56. }
  57. // p($data, 1);
  58. $result = $Permission->allowField(true)->saveAll($data);
  59. // $Permission->commit();
  60. }
  61. catch(Exception $e) {
  62. $Permission->rollback();
  63. }
  64. if ($result) {
  65. return $this->ApiJson(0,'成功');
  66. }
  67. return $this->ApiJson(-1,'失败');
  68. }
  69. }