SystemSupplier.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\supplier;
  12. use app\controller\admin\AuthController;
  13. use app\services\supplier\LoginServices;
  14. use app\services\supplier\SystemSupplierServices;
  15. use think\facade\App;
  16. /**
  17. * 供应商管理控制器
  18. * Class SystemSupplier
  19. * @package app\controller\admin\v1\supplier
  20. */
  21. class SystemSupplier extends AuthController
  22. {
  23. /**
  24. * 构造方法
  25. * SystemSupplier constructor.
  26. * @param App $app
  27. * @param SystemSupplierServices $services
  28. */
  29. public function __construct(App $app, SystemSupplierServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 获取供应商列表
  36. * @return mixed
  37. */
  38. public function index()
  39. {
  40. $where = $this->request->getMore([
  41. [['keywords', 's'], ''],
  42. ]);
  43. $where['is_del'] = 0;
  44. return $this->success($this->services->getSupplierList($where, ['id', 'supplier_name', 'name', 'phone', 'address', 'is_show', 'add_time', 'mark', 'sort']));
  45. }
  46. /**
  47. * 保存供应商
  48. * @return mixed
  49. */
  50. public function save()
  51. {
  52. $data = $this->request->postMore([
  53. ['supplier_name', ''],
  54. ['account', ''],
  55. ['name', ''],
  56. ['phone', ''],
  57. ['conf_pwd', ''],
  58. ['pwd', ''],
  59. ['email', ''],
  60. ['roles', []],
  61. ['is_show', 0],
  62. ['sort', 0],
  63. ['address', ''],
  64. ['province', 0],
  65. ['city', 0],
  66. ['area', 0],
  67. ['street', 0],
  68. ['detailed_address', ''],
  69. ['mark', '']
  70. ]);
  71. $this->validate($data, \app\validate\supplier\SystemSupplierValidate::class, 'save');
  72. if (!$data['pwd']) {
  73. return $this->fail('请输入登录密码');
  74. }
  75. if ($data['conf_pwd'] != $data['pwd']) {
  76. return $this->fail('两次输入的密码不相同');
  77. }
  78. $this->services->create($data);
  79. return $this->success('添加成功');
  80. }
  81. /**
  82. * 修改供应商信息
  83. * @param $id
  84. * @return mixed
  85. */
  86. public function update($id)
  87. {
  88. if (!$id) return $this->fail('缺少参数');
  89. $data = $this->request->postMore([
  90. ['supplier_name', ''],
  91. ['account', ''],
  92. ['name', ''],
  93. ['phone', ''],
  94. ['conf_pwd', ''],
  95. ['pwd', ''],
  96. ['email', ''],
  97. ['roles', []],
  98. ['is_show', 0],
  99. ['sort', 0],
  100. ['address', ''],
  101. ['province', 0],
  102. ['city', 0],
  103. ['area', 0],
  104. ['street', 0],
  105. ['detailed_address', ''],
  106. ['mark', '']
  107. ]);
  108. $this->validate($data, \app\validate\supplier\SystemSupplierValidate::class, 'admin_update');
  109. if ($data['pwd']) {
  110. if (!$data['conf_pwd']) {
  111. return $this->fail('请输入确认密码');
  112. }
  113. if ($data['conf_pwd'] != $data['pwd']) {
  114. return $this->fail('上次输入的密码不相同');
  115. }
  116. }
  117. $this->services->save((int)$id, $data);
  118. return $this->success('修改成功');
  119. }
  120. /**
  121. * 删除供应商
  122. * @param $id
  123. * @return mixed
  124. */
  125. public function delete($id)
  126. {
  127. if (!$id) return $this->fail('删除失败,缺少参数');
  128. $this->services->delete((int)$id);
  129. return $this->success('删除成功!');
  130. }
  131. /**
  132. * 修改状态
  133. * @param $id
  134. * @param $status
  135. * @return mixed
  136. */
  137. public function set_status($id, $status)
  138. {
  139. $this->services->update((int)$id, ['is_show' => $status]);
  140. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  141. }
  142. /**
  143. * 获取供应商信息
  144. * @return mixed
  145. */
  146. public function read($id)
  147. {
  148. if (!$id) return $this->fail('缺少参数');
  149. $info = $this->services->getSupplierInfo((int)$id, 'id, supplier_name, name, phone, admin_id, email, address, province, city, area, street, detailed_address, sort, is_show, mark', ['admin']);
  150. $info->hidden(['roles', 'admin_is_del', 'admin_type', 'level','admin_id']);
  151. $info = $info->toArray();
  152. $info['pwd'] = '';
  153. return $this->success($info);
  154. }
  155. /**
  156. * 供应商选择列表
  157. * @return mixed
  158. */
  159. public function search()
  160. {
  161. return $this->success($this->services->getSupplierSearch(['is_del' => 0], ['id', 'supplier_name']));
  162. }
  163. /**
  164. * 供应登录
  165. * @param LoginServices $services
  166. * @param $id
  167. * @return mixed
  168. * @throws \think\db\exception\DataNotFoundException
  169. * @throws \think\db\exception\ModelNotFoundException
  170. */
  171. public function supplierLogin(LoginServices $services, $id)
  172. {
  173. $supplierInfo = $this->services->getOne(['id' => $id, 'is_del' => 0], '*', ['admin']);
  174. if (!$supplierInfo || !$supplierInfo->account || $supplierInfo->admin_is_del) {
  175. return $this->fail('供应商管理员异常');
  176. }
  177. return $this->success($services->login($supplierInfo['account'], '', 'supplier'));
  178. }
  179. }