Supplier.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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\supplier\system;
  12. use app\controller\supplier\AuthController;
  13. use app\services\supplier\SystemSupplierServices;
  14. use think\facade\App;
  15. /**
  16. * 供应商控制器
  17. * Class Supplier
  18. * @package app\controller\supplier
  19. */
  20. class Supplier extends AuthController
  21. {
  22. /**
  23. * 构造方法
  24. * Supplier constructor.
  25. * @param App $app
  26. * @param SystemSupplierServices $supplierServices
  27. */
  28. public function __construct(App $app, SystemSupplierServices $supplierServices)
  29. {
  30. parent::__construct($app);
  31. $this->services = $supplierServices;
  32. }
  33. /**
  34. * 获取供应商信息
  35. * @return void
  36. */
  37. public function read()
  38. {
  39. $info = $this->services->getSupplierInfo((int)$this->supplierId);
  40. return $this->success($info->toArray());
  41. }
  42. /**
  43. * 更新供应商信息
  44. * @return void
  45. */
  46. public function update()
  47. {
  48. $data = $this->request->postMore([
  49. ['supplier_name', ''],
  50. ['name', ''],
  51. ['phone', ''],
  52. ['email', ''],
  53. ['address', ''],
  54. ['province', 0],
  55. ['city', 0],
  56. ['area', 0],
  57. ['street', 0],
  58. ['detailed_address', ''],
  59. ]);
  60. $this->validate($data, \app\validate\supplier\SystemSupplierValidate::class, 'update');
  61. $data['address'] = str_replace([' ', '/', '\\'], '', $data['address']);
  62. $data['detailed_address'] = str_replace([' ', '/', '\\'], '', $data['detailed_address']);
  63. $this->services->update((int)$this->supplierId, $data);
  64. return $this->success('保存成功');
  65. }
  66. /**
  67. * 获取供应商财务信息
  68. * @return mixed
  69. */
  70. public function getFinanceInfo()
  71. {
  72. $Info = $this->services->get((int)$this->supplierId);
  73. if (!$Info) {
  74. return app('json')->fail('供应商不存在');
  75. }
  76. return app('json')->success($Info->toArray());
  77. }
  78. /**
  79. * 设置供应商财务信息
  80. * @return mixed
  81. */
  82. public function setFinanceInfo()
  83. {
  84. $data = $this->request->postMore([
  85. ['bank_name', ''],
  86. ['bank_code', ''],
  87. ['bank_address', ''],
  88. ['alipay_account', ''],
  89. ['alipay_qrcode_url', ''],
  90. ['wechat', ''],
  91. ['wechat_qrcode_url', '']
  92. ]);
  93. $Info = $this->services->get((int)$this->supplierId);
  94. if (!$Info) {
  95. return app('json')->fail('供应商不存在');
  96. }
  97. if ($this->services->update($Info['id'], $data)) {
  98. return app('json')->success('设置成功');
  99. } else {
  100. return app('json')->fail('设置失败');
  101. }
  102. }
  103. }