MerchantController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\MemberValidator;
  5. use App\Http\Validator\MerchantValidator;
  6. use App\Services\Api\MemberService;
  7. use App\Services\Api\MerchantCategoryService;
  8. use App\Services\Api\MerchantService;
  9. /**
  10. * 商家商户管理
  11. * Class MerchantController
  12. * @package App\Http\Controllers\Api
  13. */
  14. class MerchantController extends webApp
  15. {
  16. /**
  17. * 信息
  18. * @return array
  19. */
  20. public function info()
  21. {
  22. $type = request()->post('type', 'detail');
  23. $id = request()->post('id', 0);
  24. $info = MerchantService::make()->getInfoById($id, $type, $this->userId);
  25. if($info){
  26. return showJson(1010, true, $info);
  27. }else{
  28. return showJson(2216, false, [],'404');
  29. }
  30. }
  31. /**
  32. * 管理主页数据
  33. * @return array
  34. */
  35. public function index()
  36. {
  37. $info = MemberService::make()->getInfo($this->userId, 'home');
  38. if($info){
  39. return showJson(1010, true, $info);
  40. }else{
  41. return showJson(1004, false, [],'403');
  42. }
  43. }
  44. /**
  45. * 商户分类
  46. * @return array
  47. */
  48. public function category()
  49. {
  50. $params = request()->all();
  51. $type = isset($params['show_type'])? $params['show_type'] : 1;
  52. $data = MerchantCategoryService::make()->getOptions($type);
  53. return showJson(1010, true, $data);
  54. }
  55. /**
  56. * 列表数据
  57. * @return array
  58. */
  59. public function list()
  60. {
  61. $pageSize = request()->post('pageSize', 12);
  62. $params = request()->all();
  63. $datas = MerchantService::make()->getDataList($params, $pageSize);
  64. return showJson(1010, true, $datas);
  65. }
  66. /**
  67. * 申请入驻
  68. * @return array
  69. */
  70. public function apply(MerchantValidator $validator)
  71. {
  72. $params = request()->all();
  73. $params = $validator->check($params, 'apply');
  74. if (!is_array($params)) {
  75. return showJson($params, false);
  76. }
  77. if(!$result = MerchantService::make()->apply($this->userId, $params)){
  78. return showJson(MerchantService::make()->getError(), false);
  79. }else{
  80. return showJson(MerchantService::make()->getError(), true, $result);
  81. }
  82. }
  83. /**
  84. * 入驻信息
  85. * @return array
  86. */
  87. public function applyInfo()
  88. {
  89. $info = MerchantService::make()->getApplyInfo($this->userId);
  90. if($info){
  91. return showJson(1010, true, $info);
  92. }else{
  93. return showJson(1009, false);
  94. }
  95. }
  96. /**
  97. * 申请入驻审核
  98. * @return array
  99. */
  100. public function applyConfirm(MerchantValidator $validator)
  101. {
  102. $params = request()->all();
  103. $params = $validator->check($params, 'info');
  104. if (!is_array($params)) {
  105. return showJson($params, false);
  106. }
  107. if(!$result = MerchantService::make()->applyConfirm($this->userId, $params)){
  108. return showJson(MerchantService::make()->getError(), false);
  109. }else{
  110. return showJson(MerchantService::make()->getError(), true, $result);
  111. }
  112. }
  113. /**
  114. * 冻结/解冻申请
  115. * @return array
  116. */
  117. public function lock(MerchantValidator $validator)
  118. {
  119. $params = request()->all();
  120. $params = $validator->check($params, 'info');
  121. if (!is_array($params)) {
  122. return showJson($params, false);
  123. }
  124. if(!$result = MerchantService::make()->lock($this->userId, $params)){
  125. return showJson(MerchantService::make()->getError(), false);
  126. }else{
  127. return showJson(MerchantService::make()->getError(), true, $result);
  128. }
  129. }
  130. /**
  131. * 修改账号信息
  132. * @param $userId
  133. * @param $params
  134. * @return bool
  135. */
  136. public function modify(MemberValidator $validator)
  137. {
  138. $params = request()->all();
  139. $params = $validator->check($params, 'info');
  140. if (!is_array($params)) {
  141. return showJson($params, false);
  142. }
  143. if(!MerchantService::make()->modify($this->userId, $params)){
  144. return showJson(MerchantService::make()->getError(),false);
  145. }else{
  146. return showJson(MerchantService::make()->getError(),true);
  147. }
  148. }
  149. /**
  150. * 修改店铺信息
  151. * @param $userId
  152. * @param $params
  153. * @return bool
  154. */
  155. public function saveInfo(MemberValidator $validator)
  156. {
  157. $params = request()->all();
  158. $params = $validator->check($params, 'info');
  159. if (!is_array($params)) {
  160. return showJson($params, false);
  161. }
  162. if(!MerchantService::make()->saveInfo($this->userId, $params)){
  163. return showJson(MerchantService::make()->getError(),false);
  164. }else{
  165. return showJson(MerchantService::make()->getError(),true);
  166. }
  167. }
  168. /**
  169. * 收藏点赞
  170. * @param MerchantValidator $validator
  171. * @return array
  172. */
  173. public function collect(MerchantValidator $validator)
  174. {
  175. $params = request()->all();
  176. $params = $validator->check($params, 'collect');
  177. if (!is_array($params)) {
  178. return showJson($params, false);
  179. }
  180. if(!$result = MerchantService::make()->collect($this->userId, $params)){
  181. return showJson(MerchantService::make()->getError(), false);
  182. }else{
  183. return showJson(MerchantService::make()->getError(), true, $result);
  184. }
  185. }
  186. /**
  187. * 缴纳保证金
  188. * @param MemberValidator $validator
  189. * @return array
  190. */
  191. public function deposit(MemberValidator $validator)
  192. {
  193. $params = request()->all();
  194. $params = $validator->check($params, 'deposit');
  195. if (!is_array($params)) {
  196. return showJson($params, false);
  197. }
  198. if(!$result = MerchantService::make()->deposit($this->userId, $params)){
  199. return showJson(MerchantService::make()->getError(),false);
  200. }else{
  201. return showJson(MerchantService::make()->getError(),true, $result);
  202. }
  203. }
  204. /**
  205. * 退还保证金
  206. * @param MemberValidator $validator
  207. * @return array
  208. */
  209. public function rebackDeposit(MemberValidator $validator)
  210. {
  211. $params = request()->all();
  212. $params = $validator->check($params, 'reback_deposit');
  213. if (!is_array($params)) {
  214. return showJson($params, false);
  215. }
  216. if(!$result = MerchantService::make()->rebackDeposit($this->userId, $params)){
  217. return showJson(MerchantService::make()->getError(),false);
  218. }else{
  219. return showJson(MerchantService::make()->getError(),true);
  220. }
  221. }
  222. }