ChainManage.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /*
  3. * 门店管理中心
  4. */
  5. namespace app\api\controller;
  6. use think\facade\Lang;
  7. class ChainManage extends MobileChain {
  8. public function initialize() {
  9. parent::initialize();
  10. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/chain.lang.php');
  11. }
  12. /**
  13. * @api {POST} api/ChainManage/apply_again 重新申请
  14. * @apiVersion 1.0.0
  15. * @apiGroup ChainManage
  16. *
  17. * @apiHeader {String} X-DS-KEY 门店授权token
  18. *
  19. * @apiParam {String} chain_name 门店登录账号
  20. * @apiParam {String} chain_truename 真实姓名
  21. * @apiParam {String} chain_mobile 手机号
  22. * @apiParam {String} chain_telephony 座机号
  23. * @apiParam {String} chain_addressname 门店名称
  24. * @apiParam {String} chain_area_2 城市ID
  25. * @apiParam {String} chain_area_3 地区ID
  26. * @apiParam {String} chain_area_info 地区名称
  27. * @apiParam {String} chain_address 详细地址
  28. * @apiParam {String} chain_idcard 身份证号码
  29. * @apiParam {String} chain_idcardimage 身份证图片
  30. * @apiParam {String} chain_latitude 经度
  31. * @apiParam {String} chain_longitude 纬度
  32. * @apiParam {String} password 密码
  33. * @apiParam {String} confirm_password 确认密码
  34. *
  35. * @apiSuccess {String} code 返回码,10000为成功
  36. * @apiSuccess {String} message 返回消息
  37. * @apiSuccess {Object} result 返回数据
  38. */
  39. public function apply_again() {
  40. $chain_id = $this->chain_info['chain_id'];
  41. if ($chain_id <= 0) {
  42. ds_json_encode(10001, lang('ds_common_op_fail'));
  43. }
  44. $update = array();
  45. $update['chain_name'] = input('post.chain_name');
  46. $update['chain_truename'] = input('post.chain_truename');
  47. $update['chain_mobile'] = input('post.chain_mobile');
  48. $update['chain_telephony'] = input('post.chain_telephony');
  49. $update['chain_addressname'] = input('post.chain_addressname');
  50. $update['chain_area_2'] = input('post.chain_area_2');
  51. $update['chain_area_3'] = input('post.chain_area_3');
  52. $update['chain_area_info'] = input('post.chain_area_info');
  53. $update['chain_address'] = input('post.chain_address');
  54. $update['chain_idcard'] = input('post.chain_idcard');
  55. $update['chain_addtime'] = TIMESTAMP;
  56. $update['chain_state'] = 10;
  57. $update['chain_failreason'] = '';
  58. $update['chain_idcardimage'] = input('post.chain_idcardimage', '');
  59. $update['chain_latitude'] = input('post.chain_latitude', '');
  60. $update['chain_longitude'] = input('post.chain_longitude', '');
  61. if (input('post.password')) {
  62. if (input('post.password') != input('post.confirm_password')) {
  63. ds_json_encode(10001, lang('password_not_same'));
  64. }
  65. $update['chain_passwd'] = md5(input('post.password'));
  66. }
  67. //验证数据 BEGIN
  68. $chain_validate = ds_validate('chain');
  69. if (!$chain_validate->scene('chain_apply_again')->check($update)) {
  70. ds_json_encode(10001, $chain_validate->getError());
  71. }
  72. $result = model('chain')->editChain($update, array('chain_id' => $chain_id));
  73. if ($result) {
  74. ds_json_encode(10000, lang('wait_for_verify'));
  75. } else {
  76. ds_json_encode(10001, lang('ds_common_op_fail'));
  77. }
  78. }
  79. /**
  80. * @api {POST} api/ChainManage/setting 门店设置
  81. * @apiVersion 1.0.0
  82. * @apiGroup ChainManage
  83. *
  84. * @apiHeader {String} X-DS-KEY 门店授权token
  85. *
  86. * @apiParam {String} chain_mobile 手机号
  87. * @apiParam {String} chain_telephony 座机号
  88. * @apiParam {String} chain_addressname 门店名称
  89. * @apiParam {String} chain_area_2 城市ID
  90. * @apiParam {String} chain_area_3 地区ID
  91. * @apiParam {String} chain_area_info 地区名称
  92. * @apiParam {String} chain_address 详细地址
  93. * @apiParam {String} chain_latitude 经度
  94. * @apiParam {String} chain_longitude 纬度
  95. *
  96. * @apiSuccess {String} code 返回码,10000为成功
  97. * @apiSuccess {String} message 返回消息
  98. * @apiSuccess {Object} result 返回数据
  99. */
  100. public function setting() {
  101. $chain_id = $this->chain_info['chain_id'];
  102. if ($chain_id <= 0) {
  103. ds_json_encode(10001, lang('ds_common_op_fail'));
  104. }
  105. $update = array();
  106. $update['chain_if_pickup'] = input('post.chain_if_pickup');
  107. $update['chain_if_collect'] = input('post.chain_if_collect');
  108. $update['chain_mobile'] = input('post.chain_mobile');
  109. $update['chain_telephony'] = input('post.chain_telephony');
  110. $update['chain_addressname'] = input('post.chain_addressname');
  111. $update['chain_area_2'] = input('post.chain_area_2');
  112. $update['chain_area_3'] = input('post.chain_area_3');
  113. $update['chain_area_info'] = input('post.chain_area_info');
  114. $update['chain_address'] = input('post.chain_address');
  115. $update['chain_latitude'] = input('post.chain_latitude', '');
  116. $update['chain_longitude'] = input('post.chain_longitude', '');
  117. //验证数据 BEGIN
  118. $chain_validate = ds_validate('chain');
  119. if (!$chain_validate->scene('chain_setting')->check($update)) {
  120. ds_json_encode(10001, $chain_validate->getError());
  121. }
  122. $result = model('chain')->editChain($update, array('chain_id' => $chain_id));
  123. if ($result) {
  124. ds_json_encode(10000, lang('ds_common_op_succ'),array('info' => $this->getChainUser(array_merge($this->chain_info,$update))));
  125. } else {
  126. ds_json_encode(10001, lang('ds_common_op_fail'));
  127. }
  128. }
  129. /**
  130. * @api {POST} api/ChainManage/information 门店信息
  131. * @apiVersion 1.0.0
  132. * @apiGroup ChainManage
  133. *
  134. * @apiHeader {String} X-DS-KEY 门店授权token
  135. *
  136. * @apiSuccess {String} code 返回码,10000为成功
  137. * @apiSuccess {String} message 返回消息
  138. * @apiSuccess {Object} result 返回数据
  139. */
  140. public function information() {
  141. $chain_model = model('chain');
  142. $chain_info = $this->chain_info;
  143. if ($chain_info['chain_idcardimage']) {
  144. $chain_info['chain_idcardimage_url'] = get_chain_imageurl($chain_info['chain_idcardimage']);
  145. }
  146. ds_json_encode(10000, '', array('chain_info' => $chain_info, 'info' => $this->getChainUser($chain_info)));
  147. }
  148. /**
  149. * @api {POST} api/ChainManage/change_password 更换密码
  150. * @apiVersion 1.0.0
  151. * @apiGroup ChainManage
  152. *
  153. * @apiHeader {String} X-DS-KEY 门店授权token
  154. *
  155. * @apiParam {String} password 新密码
  156. * @apiParam {String} passwd_confirm 确认密码
  157. * @apiParam {String} old_password 旧密码
  158. *
  159. * @apiSuccess {String} code 返回码,10000为成功
  160. * @apiSuccess {String} message 返回消息
  161. * @apiSuccess {Object} result 返回数据
  162. */
  163. public function change_password() {
  164. if (input('post.password') != input('post.passwd_confirm')) {
  165. ds_json_encode(10001, lang('password_not_same'));
  166. }
  167. $chain_model = model('chain');
  168. $condition = array();
  169. $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
  170. $condition[] = array('chain_passwd', '=', md5(input('post.old_password')));
  171. $dp_info = $chain_model->getChainInfo($condition);
  172. if (empty($dp_info)) {
  173. ds_json_encode(10001, lang('old_password_wrong'));
  174. }
  175. $chain_model->editChain(array('chain_passwd' => md5(input('post.password'))), $condition);
  176. ds_json_encode(10000, lang('ds_common_op_succ'));
  177. }
  178. /**
  179. * @api {POST} api/ChainManage/logout 注销
  180. * @apiVersion 1.0.0
  181. * @apiGroup ChainManage
  182. *
  183. * @apiHeader {String} X-DS-KEY 门店授权token
  184. *
  185. * @apiParam {String} client 客户端类型 android wap wechat ios windows jswechat
  186. *
  187. * @apiSuccess {String} code 返回码,10000为成功
  188. * @apiSuccess {String} message 返回消息
  189. * @apiSuccess {Object} result 返回数据
  190. */
  191. public function logout() {
  192. $mbchaintoken_model = model('mbchaintoken');
  193. $condition = array();
  194. $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
  195. $condition[] = array('chain_clienttype', '=', input('param.client_type'));
  196. $mbchaintoken_model->delMbchaintoken($condition);
  197. ds_json_encode(10000, '', 1);
  198. }
  199. }