SystemSupplier.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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', 'valid_time']));
  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. ['valid_time', ''],
  70. ['mark', '']
  71. ]);
  72. $this->validate($data, \app\validate\supplier\SystemSupplierValidate::class, 'save');
  73. if (!$data['pwd']) {
  74. return $this->fail('请输入登录密码');
  75. }
  76. if ($data['conf_pwd'] != $data['pwd']) {
  77. return $this->fail('两次输入的密码不相同');
  78. }
  79. $this->services->create($data);
  80. return $this->success('添加成功');
  81. }
  82. /**
  83. * 修改供应商信息
  84. * @param $id
  85. * @return mixed
  86. */
  87. public function update($id)
  88. {
  89. if (!$id) return $this->fail('缺少参数');
  90. $data = $this->request->postMore([
  91. ['supplier_name', ''],
  92. ['account', ''],
  93. ['name', ''],
  94. ['phone', ''],
  95. ['conf_pwd', ''],
  96. ['pwd', ''],
  97. ['email', ''],
  98. ['roles', []],
  99. ['is_show', 0],
  100. ['sort', 0],
  101. ['address', ''],
  102. ['province', 0],
  103. ['city', 0],
  104. ['area', 0],
  105. ['street', 0],
  106. ['valid_time', 0],
  107. ['detailed_address', ''],
  108. ['mark', '']
  109. ]);
  110. $this->validate($data, \app\validate\supplier\SystemSupplierValidate::class, 'admin_update');
  111. if ($data['pwd']) {
  112. if (!$data['conf_pwd']) {
  113. return $this->fail('请输入确认密码');
  114. }
  115. if ($data['conf_pwd'] != $data['pwd']) {
  116. return $this->fail('上次输入的密码不相同');
  117. }
  118. }
  119. $this->services->save((int)$id, $data);
  120. return $this->success('修改成功');
  121. }
  122. /**
  123. * 删除供应商
  124. * @param $id
  125. * @return mixed
  126. */
  127. public function delete($id)
  128. {
  129. if (!$id) return $this->fail('删除失败,缺少参数');
  130. $this->services->delete((int)$id);
  131. return $this->success('删除成功!');
  132. }
  133. /**
  134. * 修改状态
  135. * @param $id
  136. * @param $status
  137. * @return mixed
  138. */
  139. public function set_status($id, $status)
  140. {
  141. $this->services->update((int)$id, ['is_show' => $status]);
  142. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  143. }
  144. /**
  145. * 获取供应商信息
  146. * @return mixed
  147. */
  148. public function read($id)
  149. {
  150. if (!$id) return $this->fail('缺少参数');
  151. $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']);
  152. $info->hidden(['roles', 'admin_is_del', 'admin_type', 'level', 'admin_id']);
  153. $info = $info->toArray();
  154. $info['pwd'] = '';
  155. return $this->success($info);
  156. }
  157. /**
  158. * 供应商选择列表
  159. * @return mixed
  160. */
  161. public function search()
  162. {
  163. return $this->success($this->services->getSupplierSearch(['is_del' => 0], ['id', 'supplier_name']));
  164. }
  165. /**
  166. * 供应登录
  167. * @param LoginServices $services
  168. * @param $id
  169. * @return mixed
  170. * @throws \think\db\exception\DataNotFoundException
  171. * @throws \think\db\exception\ModelNotFoundException
  172. */
  173. public function supplierLogin(LoginServices $services, $id)
  174. {
  175. $supplierInfo = $this->services->getOne(['id' => $id, 'is_del' => 0], '*', ['admin']);
  176. if (!$supplierInfo || !$supplierInfo->account || $supplierInfo->admin_is_del) {
  177. return $this->fail('供应商管理员异常');
  178. }
  179. return $this->success($services->login($supplierInfo['account'], '', 'supplier'));
  180. }
  181. }