Merchant.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/25
  7. *
  8. *
  9. */
  10. namespace app\controller\merchant\system;
  11. use app\common\repositories\store\MerchantTakeRepository;
  12. use app\common\repositories\system\config\ConfigClassifyRepository;
  13. use app\validate\merchant\MerchantTakeValidate;
  14. use crmeb\basic\BaseController;
  15. use app\common\repositories\system\merchant\MerchantRepository;
  16. use app\validate\merchant\MerchantUpdateValidate;
  17. use crmeb\jobs\ChangeMerchantStatusJob;
  18. use think\App;
  19. use think\facade\Db;
  20. use think\facade\Queue;
  21. /**
  22. * Class Merchant
  23. * @package app\controller\merchant\system
  24. * @author xaboy
  25. * @day 2020/6/25
  26. */
  27. class Merchant extends BaseController
  28. {
  29. /**
  30. * @var MerchantRepository
  31. */
  32. protected $repository;
  33. /**
  34. * Merchant constructor.
  35. * @param App $app
  36. * @param MerchantRepository $repository
  37. */
  38. public function __construct(App $app, MerchantRepository $repository)
  39. {
  40. parent::__construct($app);
  41. $this->repository = $repository;
  42. }
  43. /**
  44. * @return mixed
  45. * @throws \FormBuilder\Exception\FormBuilderException
  46. * @author xaboy
  47. * @day 2020/6/25
  48. */
  49. public function updateForm()
  50. {
  51. return app('json')->success(formToData($this->repository->merchantForm($this->request->merchant()->toArray())));
  52. }
  53. /**
  54. * @param MerchantUpdateValidate $validate
  55. * @return mixed
  56. * @author xaboy
  57. * @day 2020/6/25
  58. */
  59. public function update(MerchantUpdateValidate $validate)
  60. {
  61. $data = $this->request->params(['mer_info', 'service_phone', 'mer_avatar', 'mer_banner', 'mer_state']);
  62. $validate->check($data);
  63. $this->request->merchant()->save($data);
  64. Queue::push(ChangeMerchantStatusJob::class, $this->request->merId());
  65. return app('json')->success('修改成功');
  66. }
  67. /**
  68. * @return mixed
  69. * @author xaboy
  70. * @day 2020/7/21
  71. */
  72. public function info()
  73. {
  74. $merchant = $this->request->merchant();
  75. $res = $merchant->visible(['mer_name','merchant_type', 'mer_id', 'category_id', 'mer_avatar', 'mer_banner', 'mer_info','mer_type', 'uid', 'bzj'])->toArray();
  76. $res['is_show'] = Db::name('user')->where('mer_id', $res['mer_id'])->value('is_show');
  77. return app('json')->success($res);
  78. }
  79. /**
  80. * @param MerchantTakeRepository $repository
  81. * @return mixed
  82. * @author xaboy
  83. * @day 2020/8/1
  84. */
  85. public function takeInfo(MerchantTakeRepository $repository)
  86. {
  87. $merId = $this->request->merId();
  88. return app('json')->success($repository->get($merId) + merchantConfig($merId, ['tx_map_key']));
  89. }
  90. public function memberSettingsUpdate(MerchantTakeRepository $repository){
  91. $data = $this->request->params(['member_settings']);
  92. $member_settings=merchantConfig($this->request->merId(), 'member_settings');
  93. $merId = $this->request->merId();
  94. $where['mer_id']=$merId;
  95. $where['state']=1;
  96. $yeji=Db::name('enterprise_performance_divvy')->where($where)->sum('gdp');
  97. $daili=Db::name('enterprise_agent_divvy')->where($where)->sum('gdp');
  98. // 推荐奖比例+养老金比例+业绩分红总比例+代理商分红总比例≤100
  99. $bili1=$data['member_settings']['tjj'] + $data['member_settings']['ylj']+$yeji+$daili;
  100. if($bili1>100){
  101. return app('json')->fail('推荐奖比例+养老金比例+业绩分红总比例+代理商分红总比例≤100');
  102. }
  103. // // 运营中心比例+推荐代理商收益≤100-(推荐奖比例+养老金比例+业绩分红总比例+代理商分红总比例)
  104. $bili2=$data['member_settings']['yy_one']+$data['member_settings']['dls'];
  105. if($data['member_settings']['yy_kg']!=1){
  106. $bili2=$data['member_settings']['dls'];
  107. }
  108. if($bili2<=(100-$bili1)){
  109. }else{
  110. return app('json')->fail('运营中心比例+推荐代理商收益≤100-(推荐奖比例+养老金比例+业绩分红总比例+代理商分红总比例)');
  111. }
  112. $str='';
  113. $str.='修改人id:'.$this->request->adminId();
  114. $str.=' IP:'.$this->getRealIP();
  115. $str.=' 原:';
  116. $str.=json_encode($member_settings,256);
  117. $str.=' 修改后:';
  118. $str.=json_encode($data,256);
  119. Db::name('vip_log')->insert(['data'=>$str]);
  120. $repository->set($this->request->merId(), $data);
  121. return app('json')->success('设置成功');
  122. }
  123. //客户端IP
  124. public function getRealIP()
  125. {
  126. $forwarded = request()->header("x-forwarded-for");
  127. if ($forwarded) {
  128. $ip = explode(',', $forwarded)[0];
  129. } else {
  130. $ip = request()->ip();
  131. }
  132. return $ip;
  133. }
  134. public function getYejiDailiApi()
  135. {
  136. $merId = $this->request->merId();
  137. $where['mer_id']=$merId;
  138. $where['state']=1;
  139. $data['yeji']=Db::name('enterprise_performance_divvy')->where($where)->sum('gdp');
  140. $data['daili']=Db::name('enterprise_agent_divvy')->where($where)->sum('gdp');
  141. return app('json')->success($data);
  142. }
  143. public function memberSettings()
  144. {
  145. $merId = $this->request->merId();
  146. return app('json')->success(merchantConfig($merId, 'member_settings'));
  147. }
  148. /**
  149. * @param MerchantTakeValidate $validate
  150. * @param MerchantTakeRepository $repository
  151. * @return mixed
  152. * @author xaboy
  153. * @day 2020/8/1
  154. */
  155. public function take(MerchantTakeValidate $validate, MerchantTakeRepository $repository)
  156. {
  157. $data = $this->request->params(['mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
  158. $validate->check($data);
  159. $repository->set($this->request->merId(), $data);
  160. return app('json')->success('设置成功');
  161. }
  162. /*修改地址*/
  163. public function address(MerchantTakeRepository $repository){
  164. $req = $this->request->params(['lat', 'lng', 'addr']);
  165. if(isset($req['lat']) && $req['lat'] != ""){
  166. $repository->set($this->request->merId(), $req);
  167. return app('json')->success('设置成功');
  168. }else{
  169. $merchant = $this->request->merchant();
  170. $data = $merchant->visible(['lat', 'lng', 'addr'])->toArray();
  171. return app('json')->success('ok',$data);
  172. }
  173. }
  174. function sms_record(){
  175. [$page, $limit] = $this->getPage();
  176. $arr=['SMS_294055127','SMS_294055127','SMS_465371794','SMS_465392073','SMS_465430830'];
  177. $count=Db::name('sms_record')->whereIn('template',$arr)->count();
  178. $list=Db::name('sms_record')->whereIn('template',$arr)->page($page,$limit)->order('sms_record_id desc')->select();
  179. $data= compact('count', 'list');
  180. return app('json')->success('ok',$data);
  181. }
  182. /**
  183. * @param $name
  184. * @return mixed
  185. * @author xaboy
  186. * @day 2020-03-27
  187. */
  188. public function getConfigByName($name)
  189. {
  190. $merId = $this->request->merId();
  191. $data = Db::name('system_config_value')->where('config_key', $name)->where('mer_id', $merId)->value('value');
  192. if (!$data){
  193. if ($name == 'base_commission') {
  194. return app('json')->success(0);
  195. // return app('json')->success(['yanglao_rate' => 0, 'shop_bonus_rate' => 0]);
  196. } else {
  197. return app('json')->fail('配置不存在');
  198. }
  199. }
  200. else {
  201. if (is_json($data)) {
  202. $data = json_decode($data, true);
  203. }
  204. return app('json')->success($data);
  205. }
  206. }
  207. /**
  208. * @return mixed
  209. * @author xaboy
  210. * @day 2020-04-22
  211. */
  212. public function saveConfigByName()
  213. {
  214. $merId = $this->request->merId();
  215. $name = input('name');
  216. $value = input('value');
  217. if (!$name || !$value) return app('json')->fail('保存失败');
  218. switch ($name){
  219. case 'base_commission':
  220. if ((int)$value < 5) {
  221. return app('json')->fail('商户让利比例最低5%');
  222. }
  223. if ((int)$value > 100) {
  224. return app('json')->fail('商户让利比例最高100%');
  225. }
  226. break;
  227. }
  228. /** @var ConfigClassifyRepository $make */
  229. if (!in_array($name, ['base_commission'])) {
  230. return app('json')->fail('只支持修改base_commission');
  231. }
  232. if(Db::name('system_config_value')->where('config_key', $name)->where('mer_id', $merId)->find()){
  233. Db::name('system_config_value')->where('config_key', $name)->where('mer_id', $merId)->update([
  234. 'value' => (int)$value
  235. ]);
  236. }else{
  237. Db::name('system_config_value')->insert([
  238. 'config_key' => $name,
  239. 'value' => (int)$value,
  240. 'mer_id' => $merId,
  241. ]);
  242. }
  243. // /** @var ConfigClassifyRepository $make */
  244. // if (!in_array($name, ['shop_bonus_setting'])) {
  245. // switch ($name){
  246. // case 'shop_bonus_setting':
  247. // if ((int)$value['shop_bonus_rate'] < 30) {
  248. // return app('json')->fail('商户让利比例最低30%');
  249. // }
  250. // break;
  251. // }
  252. // return app('json')->fail('只支持修改shop_bonus_setting');
  253. // }
  254. // if(Db::name('system_config_value')->where('config_key', $name)->where('mer_id', $merId)->find()){
  255. // Db::name('system_config_value')->where('config_key', $name)->where('mer_id', $merId)->update([
  256. // 'value' => json_encode($value)
  257. // ]);
  258. // }else{
  259. // Db::name('system_config_value')->insert([
  260. // 'config_key' => $name,
  261. // 'value' => json_encode($value),
  262. // 'mer_id' => $merId,
  263. // ]);
  264. // }
  265. return app('json')->success('保存成功');
  266. }
  267. }