User.php 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-05-07
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\user;
  11. use app\common\model\merchant\order\OrderMerchant;
  12. use app\common\model\system\admin\Admin;
  13. use app\common\model\system\auth\Role;
  14. use app\common\model\user\UserCertification;
  15. use app\common\repositories\merchant\order\OrderMerchantRepository;
  16. use app\common\repositories\user\UserExtractRepository;
  17. use app\controller\api\merchant\sxy\Access;
  18. use app\controller\api\user\Im;
  19. use crmeb\basic\BaseController;
  20. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  21. use app\common\repositories\store\order\StoreOrderRepository;
  22. use app\common\repositories\user\UserBillRepository;
  23. use app\common\repositories\user\UserGroupRepository;
  24. use app\common\repositories\user\UserLabelRepository;
  25. use app\common\repositories\user\UserRepository;
  26. use app\common\repositories\wechat\WechatNewsRepository;
  27. use app\common\repositories\wechat\WechatUserRepository;
  28. use app\validate\admin\UserNowMoneyValidate;
  29. use app\validate\admin\UserValidate;
  30. use crmeb\services\SpreadsheetExcelService;
  31. use FormBuilder\Exception\FormBuilderException;
  32. use think\App;
  33. use think\db\exception\DataNotFoundException;
  34. use think\db\exception\DbException;
  35. use think\db\exception\ModelNotFoundException;
  36. use think\Exception;
  37. use think\facade\Cache;
  38. use think\facade\Db;
  39. use think\Log;
  40. /**
  41. * Class User
  42. * @package app\controller\admin\user
  43. * @author xaboy
  44. * @day 2020-05-07
  45. */
  46. class User extends BaseController
  47. {
  48. /**
  49. * @var UserRepository
  50. */
  51. protected $repository;
  52. /**
  53. * User constructor.
  54. * @param App $app
  55. * @param UserRepository $repository
  56. */
  57. public function __construct(App $app, UserRepository $repository)
  58. {
  59. parent::__construct($app);
  60. $this->repository = $repository;
  61. }
  62. /**
  63. * @return mixed
  64. * @throws DataNotFoundException
  65. * @throws DbException
  66. * @throws ModelNotFoundException
  67. * @author xaboy
  68. * @day 2020-05-07
  69. */
  70. public function lst()
  71. {
  72. /*
  73. * 昵称,分组,标签,地址,性别,
  74. */
  75. $where = $this->request->params([
  76. 'label_id',
  77. 'user_type',
  78. 'sex',
  79. 'is_promoter',
  80. 'country',
  81. 'pay_count',
  82. 'user_time_type',
  83. 'user_time',
  84. 'nickname',
  85. 'province',
  86. 'city',
  87. 'group_id',
  88. 'identity',
  89. 'now_money',
  90. 'account',
  91. 'user_card',
  92. 'user_rich_type',
  93. 'stockholder',
  94. 'subIdentify',
  95. 'user_group',
  96. 'is_show'
  97. ]);
  98. [$page, $limit] = $this->getPage();
  99. return app('json')->success($this->repository->getList($where, $page, $limit));
  100. }
  101. /**
  102. * 协议
  103. * @return mixed
  104. */
  105. public function xieyi(){
  106. var_dump(111);die;
  107. return app('json')->success($this->repository->getXieYi());
  108. }
  109. /**
  110. * 批量设置星级
  111. * @return mixed
  112. * @throws DbException
  113. */
  114. public function start_level(){
  115. $ids = (array)$this->request->param('ids', []);
  116. $admin_start_level = $this->request->param('admin_start_level', '0');
  117. if (!count($ids))
  118. return app('json')->fail('数据不存在');
  119. foreach ($ids as $id){
  120. $rich=Db::name('user_rich')->where('uid',$id)->count();
  121. if($rich){
  122. Db::name('user_rich')->where('uid',$id)->update(['admin_start_level'=>$admin_start_level]);
  123. }else{
  124. $insert=['uid' => $id, 'admin_start_level' => $admin_start_level];
  125. Db::name('user_rich')->insert($insert);
  126. }
  127. }
  128. return app('json')->success('修改成功');
  129. }
  130. public function spreadList($uid)
  131. {
  132. $where = $this->request->params(['level', 'keyword', 'date','identity']);
  133. [$page, $limit] = $this->getPage();
  134. return app('json')->success($this->repository->getLevelList($uid, $where, $page, $limit));
  135. }
  136. public function spreadOrder($uid)
  137. {
  138. $where = $this->request->params(['level', 'keyword', 'date']);
  139. [$page, $limit] = $this->getPage();
  140. return app('json')->success($this->repository->subOrder($uid, $page, $limit, $where));
  141. }
  142. public function clearSpread($uid)
  143. {
  144. $this->repository->update($uid, ['spread_uid' => 0]);
  145. return app('json')->success('清除成功');
  146. }
  147. /**
  148. * @param $id
  149. * @return mixed
  150. * @throws DataNotFoundException
  151. * @throws DbException
  152. * @throws FormBuilderException
  153. * @throws ModelNotFoundException
  154. * @author xaboy
  155. * @day 2020-05-09
  156. */
  157. public function updateForm($id)
  158. {
  159. if (!$this->repository->exists($id))
  160. return app('json')->fail('数据不存在');
  161. return app('json')->success(formToData($this->repository->userForm($id)));
  162. }
  163. public function get_info($id)
  164. {
  165. // ini_set('display_errors','On');
  166. //
  167. // error_reporting(E_ALL);
  168. if (!$this->repository->exists($id))
  169. return app('json')->fail('数据不存在');
  170. $user=Db::name('user')->find($id);
  171. $certification = Db::name('user_certification')->where("uid", $id)->find();
  172. $user['real_name'] = $certification['user_name'] ?? '';
  173. $user['card_id'] = $certification['user_card'] ?? '';
  174. $user_rich=Db::name('user_rich')->where('uid',$id)->find();
  175. $user['admin_start_level'] =$user_rich?$user_rich['admin_start_level']:'0';
  176. $user['user_rich_type'] =$user_rich?$user_rich['type']:'0';
  177. $user['area_manage_pics'] =[];
  178. $user['area_manage_obtain'] ='0';
  179. if($user_rich){
  180. $user['area_manage_obtain'] =$user_rich['obtain'];
  181. if($user_rich['pics']){
  182. $user['area_manage_pics']=explode(',',$user_rich['pics']);
  183. }
  184. }
  185. $code_list_province=DB::name('user')->where('user_group',6)->where('manage_address!=""')->column('manage_address');
  186. $code_list_district=DB::name('user')->where('user_group',5)->where('manage_address!=""')->column('manage_address');
  187. // 省
  188. $code_list_province_arr=[];
  189. foreach ($code_list_province as $v){
  190. $v_explode=explode(',',$v);
  191. $code_list_province_arr[$v_explode[0]][]=$v_explode[0];
  192. }
  193. //区县
  194. $code_list_district_arr=[];
  195. foreach ($code_list_district as $v){
  196. $v_explode=explode(',',$v);
  197. $code_list_district_arr[$v_explode[1]][]=$v_explode[0];
  198. }
  199. if( $user['manage_address']){
  200. $code_list_explode=explode(',',$user['manage_address']);
  201. }
  202. $regions1 = Db::name('regions') -> field('id as value,name as label')->where('level',1) ->select();
  203. $regions2 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',2) ->select();
  204. $regions3 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',3) ->select();
  205. $regions3_data=[];
  206. foreach ($regions3 as $v){
  207. $v['disabled']=false;
  208. if(isset($code_list_district_arr[$v['pid']]) && in_array($v['value'],$code_list_district_arr[$v['pid']])){
  209. if(!isset($code_list_explode[2]) || $code_list_explode[2]!=$v['value']){
  210. $v['disabled']=true;
  211. }
  212. }
  213. $regions3_data[$v['pid']][]=$v;
  214. }
  215. $regions2_data=[];
  216. foreach ($regions2 as $v){
  217. $v['children']=isset( $regions3_data[$v['value']])? $regions3_data[$v['value']]:[];
  218. $regions2_data[$v['pid']][]=$v;
  219. }
  220. $city_area=[];
  221. foreach ($regions1 as $v){
  222. $v['children']=isset( $regions2_data[$v['value']])? $regions2_data[$v['value']]:[];
  223. $city_area[]=$v;
  224. }
  225. $regions2_data2=[];
  226. foreach ($regions2 as $v){
  227. $v['disabled']=false;
  228. if(isset($code_list_province_arr[$v['pid']]) && in_array($v['value'],$code_list_province_arr[$v['pid']])){
  229. if(!isset($code_list_explode[0]) || $code_list_explode[0]!=$v['value']){
  230. $v['disabled']=true;
  231. }
  232. }
  233. $regions2_data2[$v['pid']][]=$v;
  234. }
  235. $city_area_2=[];
  236. foreach ($regions1 as $v){
  237. $v['children']=isset( $regions2_data2[$v['value']])? $regions2_data2[$v['value']]:[];
  238. $city_area_2[]=$v;
  239. }
  240. $user['city_area_1']=$city_area;
  241. $user['city_area_2']=$city_area_2;
  242. //查询当前团队的用户列表
  243. $sql = "select getUserSpreadId($id) as uids";
  244. //\think\facade\Log::info("lplpDB".$sql);
  245. try{
  246. $spread_user_list = Db::query($sql);
  247. }catch (Exception $exception){
  248. return app('json')->success($exception);
  249. }
  250. $spread_user_list = array_diff(explode(",", trim($spread_user_list[0]['uids'],'$,')), [$id]);
  251. //查询创客手机号
  252. $marker_phone_list = [];
  253. $marker_user_list = Db::name("user")->whereIn("uid", $spread_user_list)->where('is_shop_partner', 1)->select()->toArray();
  254. foreach ($marker_user_list as $k=>$v){
  255. $marker_phone_list[] = $v['account'];
  256. }
  257. $user['marker_phone_list'] = $marker_phone_list;
  258. return app('json')->success($user);
  259. }
  260. /**
  261. * @param $id
  262. * @param UserValidate $validate
  263. * @param UserLabelRepository $labelRepository
  264. * @param UserGroupRepository $groupRepository
  265. * @return mixed
  266. * @throws DbException
  267. * @author xaboy
  268. * @day 2020-05-09
  269. */
  270. public function update($id, UserValidate $validate, UserLabelRepository $labelRepository, UserGroupRepository $groupRepository)
  271. {
  272. $data = $this->request->params(['real_name', 'agent_rebate', "mer_rebate", "promoter_rebate", "cross_store", "jurisdiction", "other_jurisdictions", "xqxiaofei", 'phone', 'birthday', 'card_id', 'addres', 'mark', 'group_id', 'user_group', ['label_id', []], ['is_promoter', 0], ['maker_phone_list', []]]);
  273. $validate->check($data);
  274. if (!$this->repository->exists($id))
  275. return app('json')->fail('数据不存在');
  276. // if ($data['group_id'] && !$groupRepository->exists($data['group_id']))
  277. // return app('json')->fail('分组不存在');
  278. $label_id = (array)$data['label_id'];
  279. $maker_phone_list = (array)$data['maker_phone_list'] ?? [];
  280. foreach ($label_id as $k => $value) {
  281. $label_id[$k] = (int)$value;
  282. if (!$labelRepository->exists((int)$value))
  283. return app('json')->fail('标签不存在');
  284. }
  285. //查询当前团队的用户列表,判断当前用户是否为团队成员
  286. $sql = "select getUserSpreadId($id) as uids";
  287. $spread_user_list = Db::query($sql);
  288. $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
  289. $error_maker_phone = [
  290. 'no_registry' => [],
  291. 'no_team' => [],
  292. ];
  293. foreach ($maker_phone_list as $k => $maker_phone) {
  294. //检查手机号是否已注册
  295. $user = Db::name('user')->where('account', $maker_phone)->find();
  296. if (empty($user)) {
  297. $error_maker_phone['not_sign'][] = $maker_phone;
  298. }
  299. if (!in_array($user['uid'], explode(",", $spread_user_list))) {
  300. $error_maker_phone['no_team'][] = $maker_phone;
  301. }
  302. }
  303. if (count($error_maker_phone['no_registry']) > 0 || count($error_maker_phone['no_team']) > 0) {
  304. return app('json')->fail("创客手机号校验异常", [
  305. 'error_maker_phone' => $error_maker_phone,
  306. ]);
  307. } else {
  308. foreach ($maker_phone_list as $k => $maker_phone) {
  309. Db::name('user')
  310. ->where('account', $maker_phone)
  311. ->update([
  312. 'is_shop_partner' => 1,
  313. ]);
  314. }
  315. }
  316. unset($data['maker_phone_list']);
  317. $data['label_id'] = implode(',', $label_id);
  318. if(!$data['birthday']) unset($data['birthday']);
  319. $user_group=input('post.user_group','');
  320. if(in_array($user_group,[5,6])){
  321. $city_list=input('post.city',[]);
  322. $city_string = implode(",", $city_list);
  323. if(!$city_list){
  324. return app('json')->fail('请选择代理区域');
  325. }
  326. $code_list_count=Db::name('user')->where('manage_address', $city_string)->where('uid !='.$id)->count();
  327. if($code_list_count){
  328. return app('json')->fail('改区域已经分配给其他人了');
  329. }
  330. $data['manage_address']=$city_string;
  331. $data['up_agency_time']=date('Y-m-d H:i:s');
  332. }else{
  333. $data['up_agency_time']=null;
  334. }
  335. if ($user_group == 3) {
  336. $mer = Db::name('merchant')->where('uid', $id)->find();
  337. if ($mer)
  338. return app('json')->fail('已经是创客,不可调整成大V经理身份');
  339. $data['up_vip_time'] = date('Y-m-d H:i:s');
  340. } else {
  341. $data['up_vip_time'] = null;
  342. }
  343. if ($user_group == 4) {
  344. $new_user_group = Db::name('user')->where('uid', $id)->value('user_group');
  345. if ($new_user_group == 3)
  346. return app('json')->fail('已经是大V经理,不可调整成创客身份');
  347. $data['up_vip_time'] = date('Y-m-d H:i:s');
  348. } else {
  349. $data['up_vip_time'] = null;
  350. }
  351. $this->repository->update($id, $data);
  352. //更新身份证信息
  353. $cardData = [];
  354. if ($data['card_id']) {
  355. $cardData['user_card'] = $data['card_id'];
  356. }
  357. if ($data['real_name']) {
  358. $cardData['user_name'] = $data['real_name'];
  359. }
  360. if (!empty($cardData)) {
  361. Db::name('user_certification')->where("uid", $id)->update($cardData);
  362. }
  363. // $admin_start_level=input('post.admin_start_level',0);
  364. // if (!empty($admin_start_level)) {
  365. // }
  366. $pics=input('post.area_manage_pics',[]);
  367. $user_rich_ypdate['type']=input('post.user_rich_type',0);
  368. $user_rich_ypdate['obtain']=input('post.area_manage_obtain',0);
  369. $user_rich_ypdate['admin_start_level']=input('post.admin_start_level',0);
  370. if($pics){
  371. $user_rich_ypdate['pics']=implode(',',$pics);
  372. }
  373. $rich=Db::name('user_rich')->where('uid',$id)->count();
  374. if($rich){
  375. Db::name('user_rich')->where('uid',$id)->update($user_rich_ypdate);
  376. }else{
  377. $user_rich_ypdate['uid']=$id;
  378. Db::name('user_rich')->insert($user_rich_ypdate);
  379. }
  380. return app('json')->success('编辑成功');
  381. }
  382. public function maker_check_phone($id)
  383. {
  384. $params = $this->request->params(['phone']);
  385. $user = Db::name('user')->where('account', $params['phone'])->find();
  386. if (empty($user)) {
  387. return app('json')->fail('该用户未注册,请先邀请用户注册~');
  388. }
  389. //查询当前团队的用户列表,判断当前用户是否为团队成员
  390. $sql = "select getUserSpreadId($id) as uids";
  391. $spread_user_list = Db::query($sql);
  392. $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
  393. if (!in_array($user['uid'], explode(",", $spread_user_list))) {
  394. return app('json')->fail('该用户不属于您团队,不可设置为合伙人~');
  395. }
  396. return app('json')->success();
  397. }
  398. /**
  399. * 设为合伙人
  400. * @return mixed
  401. * @throws DataNotFoundException
  402. * @throws DbException
  403. * @throws ModelNotFoundException
  404. */
  405. public function setAreaManage()
  406. {
  407. $area_type = $this->request->param('area_type', 0);//类型 district town village
  408. $area_manage_address_ids = $this->request->param('area_manage_address_ids', 0);//
  409. $uid = $this->request->param('uid', 0);//用户id
  410. // $area_manage = Db::name('area_manage')->where('code_list', $area_manage_address_ids)->find();
  411. // if ($area_manage) {
  412. // return app('json')->fail('该地区已有代理!');
  413. // }
  414. // $area_manage = Db::name('area_manage')->where('uid', $uid)->find();
  415. // if ($area_manage) {
  416. // return app('json')->fail('该用户已经是代理了!');
  417. // }
  418. $area_manage_address_list = explode(',', $area_manage_address_ids);
  419. switch ($area_type) {
  420. case 'district':
  421. if (count($area_manage_address_list) != 3)
  422. return app('json')->fail('请输入正确的高级合伙人代理地址!');
  423. break;
  424. case 'town':
  425. if (count($area_manage_address_list) != 4)
  426. return app('json')->fail('请输入正确的中级合伙人代理地址!');
  427. break;
  428. case 'village':
  429. if (count($area_manage_address_list) != 3)
  430. return app('json')->fail('请输入正确的初级合伙人代理地址!');
  431. break;
  432. default :
  433. return app('json')->fail('请输入正确的初级合伙人代理地址!');
  434. }
  435. $end_address = Db::name('regions_new')->where('id', end($area_manage_address_list))->find();
  436. if (empty($end_address))
  437. return app('json')->fail('该地址不存在!');
  438. // 查询当时是否已有未支付的合伙人商品订单
  439. $hehuo_store_group_order = DB::name('store_order')
  440. ->alias('store_order')
  441. ->leftJoin('store_order_product store_order_product', 'store_order.order_id=store_order_product.order_id')
  442. ->where('store_order.uid', $uid)
  443. ->where('store_order.paid', 0)
  444. ->where('store_order_product.type', 'in', [11, 12, 13])
  445. ->find();
  446. if($hehuo_store_group_order)
  447. return app('json')->fail('该用户当前有待支付的合伙人商品,不可下单!');
  448. $key = 'area_manage_order:' . $area_manage_address_ids;
  449. $redis = Cache::store('redis')->handler();
  450. if (!$redis->setnx($key, 1))
  451. return app('json')->fail('该地区已有用户锁定,请稍后再试!');
  452. // 区域设置成功 记录
  453. Db::name('area_manage')->insert([
  454. 'uid' => $uid,
  455. 'type' => $area_type,
  456. 'order_sn' => '',
  457. 'code_list' => $area_manage_address_ids,
  458. 'create_time' => date('Y-m-d H:i:s')
  459. ]);
  460. Db::name('log')->insert(['data' => "后台修改{$uid}为{$area_type}区域成功,code_list:{$area_manage_address_ids}!"]);
  461. return app('json')->success('修改成功');
  462. }
  463. /**
  464. * 设为回填
  465. * @return mixed
  466. * @throws DataNotFoundException
  467. * @throws DbException
  468. * @throws ModelNotFoundException
  469. */
  470. public function setHuiTian()
  471. {
  472. $uid = $this->request->param('uid', 0);//用户id
  473. $user_rich = Db::name('user_rich')->where('uid', $uid)->find();
  474. if ($user_rich) {
  475. if ($user_rich['is_huitian'] == 1)
  476. return app('json')->fail('该用户已经是回填!');
  477. if ($user_rich['type'] != 0)
  478. return app('json')->fail('只有普通用户可以设置为回填!');
  479. Db::name('user_rich')->where('uid', $uid)->update([
  480. 'type' => 4,
  481. 'is_huitian' => 1,
  482. ]);
  483. } else {
  484. Db::name('user_rich')->where('uid', $uid)->insert([
  485. 'uid' => $uid,
  486. 'type' => 4,
  487. 'is_huitian' => 1,
  488. ]);
  489. }
  490. Db::name('log')->insert(['data' => "后台修改{$uid}为回填成功!"]);
  491. return app('json')->success('修改成功');
  492. }
  493. /**
  494. * @param $id
  495. * @param UserLabelRepository $labelRepository
  496. * @return mixed
  497. * @throws DbException
  498. * @author xaboy
  499. * @day 2020-05-08
  500. */
  501. public function changeLabel($id, UserLabelRepository $labelRepository)
  502. {
  503. $label_id = (array)$this->request->param('label_id', []);
  504. if (!$this->repository->exists($id))
  505. return app('json')->fail('数据不存在');
  506. foreach ($label_id as $k => $value) {
  507. $label_id[$k] = (int)$value;
  508. if (!$labelRepository->exists((int)$value))
  509. return app('json')->fail('标签不存在');
  510. }
  511. $label_id = implode(',', $label_id);
  512. $this->repository->update($id, compact('label_id'));
  513. return app('json')->success('修改成功');
  514. }
  515. /**
  516. * @param UserLabelRepository $labelRepository
  517. * @return mixed
  518. * @throws DbException
  519. * @author xaboy
  520. * @day 2020-05-08
  521. */
  522. public function batchChangeLabel(UserLabelRepository $labelRepository)
  523. {
  524. $label_id = (array)$this->request->param('label_id', []);
  525. $ids = (array)$this->request->param('ids', []);
  526. if (!count($ids))
  527. return app('json')->fail('数据不存在');
  528. foreach ($label_id as $k => $value) {
  529. $label_id[$k] = (int)$value;
  530. if (!$labelRepository->exists((int)$value))
  531. return app('json')->fail('标签不存在');
  532. }
  533. $this->repository->batchChangeLabelId($ids, $label_id);
  534. return app('json')->success('修改成功');
  535. }
  536. /**
  537. * @param $id
  538. * @return mixed
  539. * @throws DataNotFoundException
  540. * @throws DbException
  541. * @throws FormBuilderException
  542. * @throws ModelNotFoundException
  543. * @author xaboy
  544. * @day 2020-05-08
  545. */
  546. public function changeLabelForm($id)
  547. {
  548. if (!$this->repository->exists($id))
  549. return app('json')->fail('数据不存在');
  550. return app('json')->success(formToData($this->repository->changeLabelForm($id)));
  551. }
  552. /**
  553. * @return mixed
  554. * @throws DataNotFoundException
  555. * @throws DbException
  556. * @throws FormBuilderException
  557. * @throws ModelNotFoundException
  558. * @author xaboy
  559. * @day 2020-05-08
  560. */
  561. public function batchChangeLabelForm()
  562. {
  563. $ids = $this->request->param('ids', '');
  564. $ids = array_filter(explode(',', $ids));
  565. if (!count($ids))
  566. return app('json')->fail('数据不存在');
  567. return app('json')->success(formToData($this->repository->changeLabelForm($ids)));
  568. }
  569. /**
  570. * 批量微信入账公证处
  571. * @return mixed
  572. * @author php迷途小书童
  573. * @created 2021/3/10 15:37
  574. */
  575. public function batchGzc()
  576. {
  577. $ids = $this->request->param('ids', '');
  578. $type = $this->request->param('type', '');
  579. $ids = array_filter(explode(',', $ids));
  580. if (!count($ids))
  581. return app('json')->fail('数据不存在');
  582. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  583. foreach ($ids as $id) {
  584. $user = $this->repository->get($id);
  585. switch ($type) {
  586. case 'WX':
  587. if (!$user->wechat_user_id)
  588. return app('json')->fail('账号:'.$user->account.'暂未微信授权,操作停止');
  589. $pay_user_id = $user->wechat_user_id;
  590. break;
  591. case 'ALI':
  592. if (!$user->ali_user_id)
  593. return app('json')->fail('账号:'.$user->account.'暂未支付宝授权,操作停止');
  594. $pay_user_id = $user->ali_user_id;
  595. break;
  596. default:
  597. return app('json')->fail('请求参数错误');
  598. break;
  599. }
  600. $count = OrderMerchant::getDB()
  601. ->where('pay_user_id', $pay_user_id)
  602. ->where('paid', 1)
  603. ->where('gzc', 0)
  604. ->count();
  605. if (!$count)
  606. return app('json')->fail('账号:'.$user->account.'暂无要发起的入账信息,操作停止');
  607. $certification = UserCertification::getDB()
  608. ->where('uid', $user->uid)
  609. ->find();
  610. if (!$certification)
  611. return app('json')->fail('账号:'.$user->account.'暂未实名认证,操作停止');
  612. $OrderMerchantRepository->batchGzc($certification,$user,$type);
  613. }
  614. return app('json')->success('发起成功');
  615. }
  616. /**
  617. * @return mixed
  618. * @throws DataNotFoundException
  619. * @throws DbException
  620. * @throws FormBuilderException
  621. * @throws ModelNotFoundException
  622. * @author xaboy
  623. * @day 2020-05-08
  624. */
  625. public function batchChangeGroupForm()
  626. {
  627. $ids = $this->request->param('ids', '');
  628. $ids = array_filter(explode(',', $ids));
  629. if (!count($ids))
  630. return app('json')->fail('数据不存在');
  631. return app('json')->success(formToData($this->repository->changeGroupForm($ids)));
  632. }
  633. /**
  634. * @param $id
  635. * @param UserGroupRepository $groupRepository
  636. * @return mixed
  637. * @throws DbException
  638. * @author xaboy
  639. * @day 2020-05-07
  640. */
  641. public function changeGroup($id, UserGroupRepository $groupRepository)
  642. {
  643. $group_id = (int)$this->request->param('group_id', 0);
  644. if (!$this->repository->exists($id))
  645. return app('json')->fail('数据不存在');
  646. if ($group_id && !$groupRepository->exists($group_id))
  647. return app('json')->fail('分组不存在');
  648. $this->repository->update($id, compact('group_id'));
  649. return app('json')->success('修改成功');
  650. }
  651. /**
  652. * @param UserGroupRepository $groupRepository
  653. * @return mixed
  654. * @throws DbException
  655. * @author xaboy
  656. * @day 2020-05-07
  657. */
  658. public function batchChangeGroup(UserGroupRepository $groupRepository)
  659. {
  660. $group_id = (int)$this->request->param('group_id', 0);
  661. $ids = (array)$this->request->param('ids', []);
  662. if (!count($ids))
  663. return app('json')->fail('数据不存在');
  664. if ($group_id && !$groupRepository->exists($group_id))
  665. return app('json')->fail('分组不存在');
  666. $this->repository->batchChangeGroupId($ids, $group_id);
  667. return app('json')->success('修改成功');
  668. }
  669. /**
  670. * @param $id
  671. * @return mixed
  672. * @throws FormBuilderException
  673. * @throws DataNotFoundException
  674. * @throws DbException
  675. * @throws ModelNotFoundException
  676. * @author xaboy
  677. * @day 2020-05-07
  678. */
  679. public function changeGroupForm($id)
  680. {
  681. if (!$this->repository->exists($id))
  682. return app('json')->fail('数据不存在');
  683. return app('json')->success(formToData($this->repository->changeGroupForm($id)));
  684. }
  685. /**
  686. * @param $id
  687. * @return mixed
  688. * @throws FormBuilderException
  689. * @author xaboy
  690. * @day 2020-05-07
  691. */
  692. public function changeNowMoneyForm($id)
  693. {
  694. if (!$this->repository->exists($id))
  695. return app('json')->fail('数据不存在');
  696. return app('json')->success(formToData($this->repository->changeNowMoneyForm($id)));
  697. }
  698. /**
  699. * @param $id
  700. * @param UserNowMoneyValidate $validate
  701. * @return mixed
  702. * @throws DataNotFoundException
  703. * @throws DbException
  704. * @throws ModelNotFoundException
  705. * @author xaboy
  706. * @day 2020-05-07
  707. */
  708. public function changeNowMoney($id, UserNowMoneyValidate $validate)
  709. {
  710. $data = $this->request->params(['now_money', 'type']);
  711. $validate->check($data);
  712. if (!$this->repository->exists($id))
  713. return app('json')->fail('数据不存在');
  714. $this->repository->changeNowMoney($id, $this->request->adminId(), $data['type'], $data['now_money']);
  715. return app('json')->success('修改成功');
  716. }
  717. /**
  718. * @param $id
  719. * @return mixed
  720. * @throws FormBuilderException
  721. * @author xaboy
  722. * @day 2020-05-07
  723. */
  724. public function changeProForm($id)
  725. {
  726. if (!$this->repository->exists($id))
  727. return app('json')->fail('数据不存在');
  728. return app('json')->success(formToData($this->repository->changeProForm($id)));
  729. }
  730. /*
  731. * 更改用户推荐信息
  732. * cabbage
  733. * 2020-11-04
  734. * */
  735. public function changePro($id,UserRepository $repository)
  736. {
  737. $spread_account = $this->request->param('spread_account');
  738. if (!$spread_account || !$id){
  739. return app('json')->fail('参数丢失');
  740. }
  741. if($repository->update_spread($id,$spread_account)){
  742. return app('json')->success("修改成功");
  743. }else{
  744. return app('json')->fail("失败");
  745. }
  746. }
  747. /**
  748. * @param $id
  749. * @return mixed
  750. * @throws FormBuilderException
  751. * @author xaboy
  752. * @day 2020-05-07
  753. */
  754. public function changeProLevelForm($id)
  755. {
  756. if (!$this->repository->exists($id))
  757. return app('json')->fail('数据不存在');
  758. return app('json')->success(formToData($this->repository->changeProFormLevel($id)));
  759. }
  760. /*
  761. * 更改用户节点人信息
  762. * cabbage
  763. * 2020-11-04
  764. * */
  765. public function changeProLevel($id,UserRepository $repository)
  766. {
  767. $level_account = $this->request->param('level_account');
  768. if (!$level_account || !$id){
  769. return app('json')->fail('参数丢失');
  770. }
  771. if($repository->update_level_uid($id,$level_account)){
  772. return app('json')->success("修改成功");
  773. }else{
  774. return app('json')->fail("失败");
  775. }
  776. }
  777. /**
  778. * 修改用户奖励表单
  779. * @param $id
  780. * @return mixed
  781. * @throws FormBuilderException
  782. */
  783. public function changeAwardForm($id)
  784. {
  785. if (!$this->repository->exists($id))
  786. return app('json')->fail('数据不存在');
  787. return app('json')->success(formToData($this->repository->changeAwardForm($id)));
  788. }
  789. /**
  790. * 修改用户奖励
  791. * @param $id
  792. * @param UserRepository $repository
  793. * @return mixed
  794. */
  795. public function changeAward($id,UserRepository $repository)
  796. {
  797. $type = $this->request->param('type');
  798. $award_type = $this->request->param('award_type');
  799. $num = $this->request->param('num');
  800. $mark = $this->request->param('mark','');
  801. $admin_id = $this->request->param('admin_id');
  802. if (!$id || !$award_type || !$num){
  803. return app('json')->fail('参数丢失');
  804. }
  805. if($repository->changeAward($id,$type,$award_type,$num,$mark,$admin_id)){
  806. return app('json')->success("修改成功");
  807. }else{
  808. return app('json')->fail("失败");
  809. }
  810. }
  811. /**
  812. * @param $id
  813. * @return mixed
  814. * @throws DataNotFoundException
  815. * @throws DbException
  816. * @throws FormBuilderException
  817. * @throws ModelNotFoundException
  818. * @author xaboy
  819. * @day 2020-05-08
  820. */
  821. public function changePassForm($id)
  822. {
  823. if (!$this->repository->exists($id))
  824. return app('json')->fail('数据不存在');
  825. return app('json')->success(formToData($this->repository->changePassForm($id)));
  826. }
  827. /*
  828. * 更改用户密码
  829. * cabbage
  830. * 2021-2-23
  831. * */
  832. public function changePass($id,UserRepository $repository)
  833. {
  834. $pass_word = $this->request->param('pass_word');
  835. if (!$pass_word || !$id){
  836. return app('json')->fail('参数丢失');
  837. }
  838. if($repository->changePass($id,$pass_word)){
  839. return app('json')->success("修改成功");
  840. }else{
  841. return app('json')->fail("失败");
  842. }
  843. }
  844. /**
  845. * @param WechatNewsRepository $wechatNewsRepository
  846. * @param WechatUserRepository $wechatUserRepository
  847. * @return mixed
  848. * @author xaboy
  849. * @day 2020-05-11
  850. */
  851. public function sendNews(WechatNewsRepository $wechatNewsRepository, WechatUserRepository $wechatUserRepository)
  852. {
  853. $ids = array_filter(array_unique(explode(',', $this->request->param('ids'))));
  854. $news_id = (int)$this->request->param('news_id', 0);
  855. if (!$news_id)
  856. return app('json')->fail('请选择图文消息');
  857. if (!$wechatNewsRepository->exists($news_id))
  858. return app('json')->fail('数据不存在');
  859. if (!count($ids))
  860. return app('json')->fail('请选择微信用户');
  861. $wechatUserRepository->sendNews($news_id, $ids);
  862. return app('json')->success('发送成功');
  863. }
  864. // public function promoterList()
  865. // {
  866. // $where = $this->request->params(['keyword', 'user_type', 'status', 'sex', 'group_id']);
  867. //// $where['is_promoter'] = 1;
  868. // [$page, $limit] = $this->getPage();
  869. // return app('json')->success($this->repository->getList($where, $page, $limit));
  870. // }
  871. public function promoterList()
  872. {
  873. $where = $this->request->params(['keyword']);
  874. // $where['is_promoter'] = 1;
  875. [$page, $limit] = $this->getPage();
  876. return app('json')->success($this->repository->getAgent($where, $page, $limit));
  877. }
  878. public function promoterAgent()
  879. {
  880. $where = $this->request->params(['keyword', 'identity']);
  881. // $where['is_promoter'] = 1;
  882. [$page, $limit] = $this->getPage();
  883. return app('json')->success($this->repository->getAgentList($where, $page, $limit));
  884. }
  885. public function getPromoter($id)
  886. {
  887. // $where = $this->request->params(['id']);
  888. $where['id'] =$id;
  889. // [$page, $limit] = $this->getPage();s
  890. return app('json')->success($this->repository->getonePromoter($where));
  891. }
  892. public function updateAgent($id)
  893. {
  894. $where = $this->request->params(["status"]);
  895. $res = $this->repository->updateAgent($where,$id);
  896. if($res['code'] == 400){
  897. return app('json')->fail($res['msg']);
  898. }
  899. return app('json')->success("审核成功");
  900. }
  901. /*线下支付*/
  902. public function xianPay($id){
  903. $mark = input("mark");
  904. $res = $this->repository->xianPayAgent($id,$mark);
  905. if($res['code'] == 400){
  906. return app('json')->fail($res['msg']);
  907. }
  908. return app('json')->success("线下支付成功");
  909. }
  910. public function detail($id)
  911. {
  912. if (!$this->repository->exists($id))
  913. return app('json')->fail('数据不存在');
  914. $data = $this->repository->userOrderDetail($id);
  915. $data['enterprise_user'] = null;
  916. $where=["uid"=>$id,"type"=>"commission","commission_type"=>5];
  917. $ylj=Db::name("user_bill")->where($where)->whereIn('status',[0,1])->sum('number');
  918. $data['ylj']=$ylj?$ylj:0;
  919. $revenue = Db::name("user_bill")
  920. ->where(["uid" => $id, "type" => "commission"])
  921. ->whereIn('status', [1])
  922. ->sum('number');
  923. $data['revenue']=$revenue?$revenue:0;
  924. return app('json')->success($data);
  925. }
  926. public function order($id, StoreOrderRepository $repository)
  927. {
  928. if (!$this->repository->exists($id))
  929. return app('json')->fail('数据不存在');
  930. [$page, $limit] = $this->getPage();
  931. return app('json')->success($repository->userList($id, $page, $limit));
  932. }
  933. public function coupon($id, StoreCouponUserRepository $repository)
  934. {
  935. if (!$this->repository->exists($id))
  936. return app('json')->fail('数据不存在');
  937. [$page, $limit] = $this->getPage();
  938. return app('json')->success($repository->userList($id, $page, $limit));
  939. }
  940. public function bill($id, UserBillRepository $repository)
  941. {
  942. if (!$this->repository->exists(intval($id)))
  943. return app('json')->fail('数据不存在');
  944. [$page, $limit] = $this->getPage();
  945. return app('json')->success($repository->userList([
  946. 'now_money' => 0,
  947. 'status' => 1
  948. ], $id, $page, $limit));
  949. }
  950. /**
  951. * @return mixed
  952. * @author xaboy
  953. * @day 2020/6/22
  954. */
  955. public function new_bill($id, UserBillRepository $billRepository)
  956. {
  957. [$page, $limit] = $this->getPage();
  958. $where = [
  959. // 'now_money' => $this->request->param('type', 0),
  960. 'status' => $this->request->param('status'),
  961. // 'mer_id' => $this->request->merId()
  962. 'not_commission_type' => [5, 7, 17, 19],
  963. ];
  964. if ($this->request->param('is_red') == true) {
  965. $where['is_red_brokerage'] = 1;
  966. }
  967. $bill_list = $billRepository->userList($where, $id, $page, $limit);
  968. foreach ($bill_list['list'] as $key => $item) {
  969. if ($item['status'] == 1) $bill_list['list'][$key]['jiesuan_string'] = "已结算";
  970. if ($item['status'] == 0) $bill_list['list'][$key]['jiesuan_string'] = "未结算";
  971. if ($item['status'] == -1) $bill_list['list'][$key]['jiesuan_string'] = "已失效";
  972. }
  973. return app('json')->success($bill_list);
  974. }
  975. /*
  976. * 用户养老金信息
  977. * @author cabbage
  978. * @date 2020-11-03
  979. * */
  980. public function annuity($id, UserRepository $repository)
  981. {
  982. if (!$this->repository->exists(intval($id)))
  983. return app('json')->fail('数据不存在');
  984. return app('json')->success($repository->get_yanglao($id));
  985. }
  986. /**
  987. * 养老金明细
  988. */
  989. public function annuitylog($id, UserRepository $repository){
  990. [$page, $limit] = $this->getPage();
  991. $where=["uid"=>$id,"type"=>"commission","commission_type"=>5];
  992. $res = $repository->yanglaolog($where,$page,$limit);
  993. return app('json')->success($res);
  994. }
  995. /*用户银行卡信息*/
  996. public function getAccount($id){
  997. $where['user_id']=$id;
  998. $data = app()->make(UserExtractRepository::class)->list($where);
  999. return app('json')->success($data);
  1000. }
  1001. /*设置用户身份*/
  1002. /*
  1003. * pay:1-付费。2-未付费
  1004. * type:3-银卡。4-金卡。5-商户。6-渠道商
  1005. * */
  1006. public function setIdentity(){
  1007. $data = $this->request->params(["uid","pay","type","dc_id","recommend_phone"]);
  1008. $dc_id = $data['dc_id'];
  1009. if(empty($data['uid'])){
  1010. return app('json')->fail('参数错误');
  1011. }
  1012. $time = date('Y-m-d', time());
  1013. $time = strtotime($time);
  1014. $end_time = $time + 31536000 - 1;
  1015. $recommend = Db::name('user') -> where('account',$data['recommend_phone']) -> value('uid');
  1016. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  1017. $access = new Access();
  1018. //付费
  1019. if($data['pay'] == 1){
  1020. switch ($data['type']){
  1021. case 3:
  1022. case 4:
  1023. if($data['type'] == 3){
  1024. $order['pay_price'] = '399';
  1025. }else{
  1026. $order['pay_price'] = '999';
  1027. }
  1028. $order['uid'] = $data['uid'];
  1029. $order['order_id'] = 0;
  1030. $order['order_sn'] = 'sIO'.$storeOrderRepository->getNewOrderId();
  1031. $order['mer_id'] = 0;
  1032. $order['dacang_id'] = $dc_id;
  1033. if($data['type'] == 3){
  1034. $storeOrderRepository -> dacang_yin($order,0);
  1035. }elseif($data['type'] == 4){
  1036. $storeOrderRepository -> dacang($order,0);
  1037. }
  1038. break;
  1039. case 5:
  1040. //赠送商户
  1041. $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
  1042. if(!$merchant)
  1043. Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'status'=>3,'activation_code'=>rand('000000000','999999999')]);
  1044. $mer = Db::name('user_mer') -> where('uid',$data['uid']) -> find();
  1045. if(!$mer){
  1046. Db::name('user_mer') -> insert(['uid'=>$data['uid'],'mer'=>2]);
  1047. }else{
  1048. Db::name('user_mer') -> where('uid',$data['uid'])->inc('mer', 2) ->update();
  1049. }
  1050. $order_sn = 'sIM'.$storeOrderRepository->getNewOrderId();
  1051. $insertData=[
  1052. 'mer_id'=>0,
  1053. 'pay_price'=>systemConfig("annual"),
  1054. 'status'=>1,
  1055. 'order_no'=>$order_sn,
  1056. 'uid'=>$data['uid']
  1057. ];
  1058. $id = Db::name('merchant_annual_cost_order')->insertGetId($insertData);
  1059. $access->nianfei_yj($id);
  1060. break;
  1061. case 6:
  1062. //赠送返本商户
  1063. $mer = Db::name('user_mer') -> where('uid',$data['uid']) -> find();
  1064. if(!$mer){
  1065. Db::name('user_mer') -> insert(['uid'=>$data['uid'],'mer'=>10]);
  1066. }else{
  1067. Db::name('user_mer') -> where('uid',$data['uid'])->inc('mer', 10) ->update();;
  1068. }
  1069. //赠送商户
  1070. $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
  1071. if(!$merchant)
  1072. Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'activation_code'=>rand('000000000','999999999')]);
  1073. //赠送大仓会员资格
  1074. $dacang_user = Db::name('da_cang_user')->where('uid', $data['uid'])->find();
  1075. $dc_id = 1;
  1076. //如果不是金卡会员,赠送金卡会员一年
  1077. if (!$dacang_user) {
  1078. Db::name('da_cang_user')->insert(['uid' => $data['uid'], 'ctime' => time(), 'end_time' => $end_time, 'dc_id' => $dc_id,'status'=>1,'type'=>1]);
  1079. }else{
  1080. //如果是银卡会员,变成金卡,一年 || 是否已过期,如果已过期,赠送金卡会员一年
  1081. if($dacang_user['type'] == 2 || $dacang_user['end_time'] < $time){
  1082. Db::name('da_cang_user')->where('uid', $data['uid'])->where('dc_id', $dc_id)->update(['end_time' => $end_time,'status'=>1,'type'=>1]);
  1083. }
  1084. }
  1085. $order_sn = 'sIC'.$storeOrderRepository->getNewOrderId();
  1086. $insertData=[
  1087. 'pay_price'=>systemConfig("channel_price"),
  1088. 'status'=>1,
  1089. 'order_no'=>$order_sn,
  1090. 'uid'=>$data['uid']
  1091. ];
  1092. Db::name('channel_order')->insertGetId($insertData);
  1093. //渠道商
  1094. $channel_user=Db::name('channel_user')->where('uid',$data['uid']) -> find();
  1095. if($channel_user){
  1096. Db::name('channel_user')->where('uid',$data['uid'])->update(['status'=>1]);
  1097. }else{
  1098. Db::name('channel_user')->insert(['uid'=>$data['uid'],'status'=>1,'ctime'=>time(),'recommend_uid'=>$recommend]);
  1099. }
  1100. $access->channel_fenyong($order_sn);
  1101. break;
  1102. }
  1103. return app('json')->success('付费身份设置成功');
  1104. }else{
  1105. //未付费
  1106. switch ($data['type']){
  1107. case 3:
  1108. case 4:
  1109. $dacang_user = Db::name('da_cang_user')->where('uid', $data['uid'])->find();
  1110. $type = $data['type'] == 3 ? 2 : 1;
  1111. //如果原来有大仓会员。修改
  1112. if ($dacang_user) {
  1113. Db::name('da_cang_user')->where('uid', $data['uid'])->where('dc_id', $dc_id)->update(['end_time' => $end_time,'status'=>1,'type'=>$type]);
  1114. } else {
  1115. //新会员
  1116. Db::name('da_cang_user')->insert(['uid' => $data['uid'], 'ctime' => time(), 'end_time' => $end_time, 'dc_id' => $dc_id,'status'=>1,'type'=>$type]);
  1117. }
  1118. break;
  1119. case 5:
  1120. //赠送商户
  1121. $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
  1122. if(!$merchant)
  1123. Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'status'=>3,'activation_code'=>rand('000000000','999999999')]);
  1124. break;
  1125. case 6:
  1126. //渠道商
  1127. $channel_user=Db::name('channel_user')->where('uid',$data['uid']) -> find();
  1128. if($channel_user){
  1129. Db::name('channel_user')->where('uid',$data['uid'])->update(['status'=>1]);
  1130. }else{
  1131. Db::name('channel_user')->insert(['uid'=>$data['uid'],'status'=>1,'ctime'=>time(),'recommend_uid'=>$recommend]);
  1132. }
  1133. }
  1134. return app('json')->success('未付费身份设置成功');
  1135. }
  1136. }
  1137. public function gongfu_user(){
  1138. $data = $this->request->params(["uid","red","type"]);
  1139. if(empty($data['uid']) || empty($data['type'])){
  1140. return app('json')->fail('参数错误');
  1141. }
  1142. $type = $data['type'];
  1143. $red = $data['red'];
  1144. $uid = $data['uid'];
  1145. $check = Db::name('user_rich')->where('uid',$uid)->find();
  1146. if($check){
  1147. $update['type'] = $type;
  1148. Db::name('user_rich')->where('uid',$uid)->update($update);
  1149. }else{
  1150. Db::name('user_rich')->insert(['uid' => $uid, 'type' => $type]);
  1151. }
  1152. if ($red > 0){
  1153. Db::name('user_rich')->where('uid',$uid)->inc('red', $red)->update();
  1154. Db::name('user_rich_log')->insert([
  1155. 'uid' => $uid,
  1156. 'red' => $red,
  1157. 'pm' => 1,
  1158. 'time' => time(),
  1159. 'order_id' => 0,
  1160. 'mark' => '系统赠送红积分'
  1161. ]);
  1162. }
  1163. return app('json')->success('身份设置成功');
  1164. }
  1165. public function bangfu(){
  1166. $data = $this->request->params(["uid"]);
  1167. if(empty($data['uid'])){
  1168. return app('json')->fail('参数错误');
  1169. }
  1170. $uid = $data['uid'];
  1171. $check = Db::name('user_bangfu') -> where('uid', $uid) -> find();
  1172. if (!$check){
  1173. Db::name('user_bangfu')->insert([
  1174. 'uid' => $uid,
  1175. 'time' => time(),
  1176. 'status' => 1
  1177. ]);
  1178. }
  1179. return app('json')->success('身份设置成功');
  1180. }
  1181. public function bangfu_list(){
  1182. [$page, $limit] = $this->getPage();
  1183. $list = Db::name('user_bangfu')
  1184. -> alias('ub')
  1185. -> join('user u', 'u.uid = ub.uid')
  1186. -> leftJoin('user_rich ur', 'ub.uid = ur.uid')
  1187. -> field('u.nickname,u.account,ub.status,ur.type,ub.id as uid')
  1188. -> page($page, $limit)
  1189. -> select();
  1190. return app('json')->success($list);
  1191. }
  1192. public function bangfu_examine(){
  1193. $data = $this->request->params(["uid","status"]);
  1194. if(empty($data['uid'])){
  1195. return app('json')->fail('参数错误');
  1196. }
  1197. $uid = $data['uid'];
  1198. $check = Db::name('user_bangfu') -> where('id', $uid) -> find();
  1199. if (!$check){
  1200. return app('json')->fail('不存在');
  1201. }
  1202. $save = Db::name('user_bangfu') -> where('uid', $uid) -> update(['status'=>$data['status']]);
  1203. if ($save){
  1204. return app('json')->success('修改成功');
  1205. }
  1206. return app('json')->fail('出错');
  1207. }
  1208. public function importExcel()
  1209. {
  1210. $file = request()->file('file');
  1211. if(!$file){
  1212. return app('json')->fail('请上传文件');
  1213. }
  1214. $extension = pathinfo($file->getOriginalName(), PATHINFO_EXTENSION);
  1215. if ($extension != 'xlsx' && $extension != 'xls') {
  1216. return app('json')->fail('请上传xlx或xlsx文件');
  1217. }
  1218. // 创建一个新的Excel读取器对象
  1219. $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
  1220. $objPHPExcel = $objReader->load($file);
  1221. // 选择活动工作表
  1222. $objPHPExcel->setActiveSheetIndex(0);
  1223. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  1224. // 循环遍历行和列
  1225. $yonghu=[];
  1226. foreach ($sheetData as $k=>$row) {
  1227. if($k==1){
  1228. continue;
  1229. }
  1230. if($row['A'] && $row['A']!=NULL && $row['A']!=''){
  1231. $yonghu[]=array('a'=>$row['A'],'b'=>$row['B']);
  1232. }
  1233. }
  1234. if(count($yonghu)<1){
  1235. return app('json')->fail('未获取到数据');
  1236. }
  1237. $repository = app()->make(UserRepository::class);
  1238. foreach ($yonghu as $k=>$v){
  1239. $user = $repository->accountByUser($v['a']);
  1240. if ($user){
  1241. // return app('json')->fail('手机号已存在');
  1242. $yonghu[$k]['user'] = $user;
  1243. }else{
  1244. $yonghu[$k]['user'] = $repository->registr($v['a'],'A123456','APP',0);
  1245. }
  1246. }
  1247. foreach ($yonghu as $v){
  1248. $user=$v['user'];
  1249. $spread_uid=$v['user']['spread_uid'];
  1250. if($v['b'] && $v['b']!=null && $v['b']!=''){
  1251. $pid=Db::name('user')->where('account',$v['b'])->value('uid');
  1252. if($pid){
  1253. $repository->bindSpread($user, intval($pid));
  1254. $spread_uid=$pid;
  1255. }
  1256. }
  1257. $mer_count=Db::name('merchant')->where('uid',$user['uid'])->count();
  1258. if(!$mer_count){
  1259. // $code_insert['uid']=$v['uid'];
  1260. // $code_insert['code']=time().'_'.$this->generateRandomCode(20);
  1261. // $code_insert['ctime']=time();
  1262. // $code_insert['type']=2;
  1263. // $re=Db::name('activation_code')->insertGetId($code_insert);
  1264. $mer_insert['uid']=$user['uid'];
  1265. $mer_insert['spread_uid']=$spread_uid;
  1266. $mer_id=Db::name('merchant')->insertGetId($mer_insert);
  1267. $merchant_admin_insert['mer_id']=$mer_id;
  1268. $merchant_admin_insert['uid']= $user['uid'];
  1269. $merchant_admin_insert['account']= $user['account'];
  1270. $merchant_admin_insert['real_name']= $user['account'];
  1271. $merchant_admin_insert['phone']= $user['account'];
  1272. $merchant_admin_insert['level']= 0;
  1273. $re=Db::name('merchant_admin')->insertGetId($merchant_admin_insert);
  1274. $merchant_intention['mer_id']=$mer_id;
  1275. $merchant_intention['uid']= $user['uid'];
  1276. $merchant_intention['phone']= $user['account'];
  1277. Db::name('merchant_intention')->insertGetId($merchant_intention);
  1278. // insert into rrx_merchant_admin(mer_id,uid,account,pwd,phone,real_name,level) values (#{mer_id},#{uid},#{account},#{pwd},#{phone},#{real_name},#{level})
  1279. }
  1280. }
  1281. return app('json')->success('导入成功');
  1282. }
  1283. public function getImAdmin(){
  1284. try {
  1285. $data = json_decode('{
  1286. "im_pass": 873947,
  1287. "im_user_id": "admin",
  1288. "im_uuid": "53d0f370-f104-11ee-8cd6-45641584429c"
  1289. }',true);
  1290. return app('json')->success($data);
  1291. $im = new Im();
  1292. $data = [];
  1293. $data['im_pass'] = mt_rand(100000,999999);
  1294. $data['im_user_id'] = 'admin';
  1295. $data['im_uuid']= $im->createImUser('useradmin', 'admin',$data['im_pass']);
  1296. return app('json')->success($data);
  1297. } catch (\Exception $e) {
  1298. Db::name('log')->insert(['data'=>'注册异常'.$e->getFile().$e->getMessage().$e->getLine()]);
  1299. }
  1300. return app('json')->fail('注册失败');
  1301. }
  1302. public function enterpriseUserScoreApi(){
  1303. [$page, $limit] = $this->getPage();
  1304. $where = $this->request->params(['uid']);
  1305. $list=Db::name('user_sign_score')->where($where)->page($page, $limit)->order('id desc')->select();
  1306. foreach ($list as $k=>$v){
  1307. $v['pm_text']='收入';
  1308. if($v['pm']==2 || $v['pm']==4){
  1309. $v['pm_text']='支出';
  1310. $v['reward_socre']='-'.$v['reward_socre'];
  1311. }else{
  1312. $v['pm_text']='收入';
  1313. $v['reward_socre']='+'.$v['reward_socre'];
  1314. }
  1315. if($v['order_id'] && empty($v['order_sn'])){
  1316. $v['order_sn']=Db::name('store_order')->where('order_id',$v['order_id'])->value('order_sn');
  1317. }
  1318. if(empty($v['order_sn'])){
  1319. $v['order_sn']='--';
  1320. }
  1321. $v['create_time'] = $v['settlement_time'];
  1322. $v['create_time'] = date("Y-m-d H:i:s", $v['addtime']);
  1323. $list[$k]=$v;
  1324. }
  1325. $data['list']=$list;
  1326. $data['count']=Db::name('user_sign_score')->where($where)->count();
  1327. return app('json')->success($data);
  1328. }
  1329. /**
  1330. * 获取统计导出
  1331. */
  1332. public function getStatisticsExcel($header,$arr,$title)
  1333. {
  1334. $filename = $title.'_'.date('YmdHis').'_'.rand(10000,99999);
  1335. $name = $filename;
  1336. $info = '生成时间:' . date('Y-m-d H:i:s',time());
  1337. $suffix='xlsx';
  1338. $path='extract';
  1339. unset($_instance);
  1340. $_instance = SpreadsheetExcelService::instance_xin();
  1341. $_path =$_instance
  1342. ->createOrActive()
  1343. ->setExcelHeader($header)
  1344. ->setExcelTile($title, $name, $info)
  1345. ->setExcelContent($arr)
  1346. ->excelSave($filename, $suffix, $path);
  1347. $domain = request()->domain();
  1348. $data= [
  1349. 'name' => $filename.'.'.$suffix,
  1350. 'status' => 1,
  1351. 'path' => $domain.'/'.$_path
  1352. ];
  1353. return $data;
  1354. }
  1355. /**
  1356. * 获取合伙人分红记录
  1357. * @return mixed
  1358. * @throws DataNotFoundException
  1359. * @throws DbException
  1360. * @throws ModelNotFoundException
  1361. */
  1362. public function getWeekAwardList()
  1363. {
  1364. [$page, $limit] = $this->getPage();
  1365. $nickname = request()->param('nickname', '');
  1366. $account = request()->param('account', '');
  1367. $user_group = request()->param('user_group', '');
  1368. $dateRange = request()->param('dateRange', []);
  1369. $where = [];
  1370. if ($nickname) $where[] = ['u.nickname', 'like', '%' . $nickname . '%'];
  1371. if ($account) $where[] = ['u.account', 'like', '%' . $account . '%'];
  1372. if ($user_group) $where[] = ['w.user_group', '=', $user_group];
  1373. if (!empty($dateRange)) {
  1374. $where[] = ['w.create_time', 'between', [$dateRange[0], $dateRange[1]]];
  1375. }
  1376. $query = Db::name('partner_profit_records')->alias('w')
  1377. ->leftJoin('user u', 'w.user_id=u.uid')
  1378. ->leftJoin('user_identity identity', 'identity.user_group_id=w.user_group')
  1379. ->field('w.*,u.uid,u.account,u.real_name,u.nickname,identity.user_group_name')
  1380. ->where($where);
  1381. // 导出
  1382. $is_excel = request()->param('is_excel', 0);
  1383. if ($is_excel == 1) {
  1384. $data = $query->select();
  1385. $arr = [];
  1386. foreach ($data as $item) {
  1387. $arr[] = [
  1388. $item['id'],
  1389. $item['nickname'],
  1390. $item['account'],
  1391. $item['user_group_name'], // 合伙人等级
  1392. $item['start_time'], // 账期开始时间
  1393. $item['end_time'], // 账期结束时间
  1394. $item['performance'], // 账期平台业绩
  1395. $item['red_envelope'], // 账期内发放红包
  1396. $item['reality_performance'], // 实际分红业绩
  1397. $item['dividend_ratio'], // 分红比例(%)
  1398. $item['dividend'], // 分红金额
  1399. $item['performance_part'], // 个人小区业绩
  1400. $item['performance_part_all'], // 等级内小区业绩和
  1401. $item['part_money'], // 小区业绩占比分红金额
  1402. $item['performance_total'], // 个人总业绩
  1403. $item['performance_total_all'], // 等级内总业绩和
  1404. $item['total_money'], // 总业绩占比分红金额
  1405. $item['brokerage'], // 分红佣金
  1406. $item['fugou'], // 分红复购金
  1407. $item['radio'], // 分红状态
  1408. $item['create_time'], // 创建时间
  1409. ];
  1410. }
  1411. return app('json')->success($this->getStatisticsExcel([
  1412. 'ID',
  1413. '用户昵称',
  1414. '用户账号',
  1415. '合伙人等级',
  1416. '账期开始时间',
  1417. '账期结束时间',
  1418. '账期平台业绩',
  1419. '账期内发放红包',
  1420. '实际分红业绩',
  1421. '分红比例(%)',
  1422. '分红金额',
  1423. '个人小区业绩',
  1424. '等级内小区业绩和',
  1425. '小区业绩占比分红金额',
  1426. '个人总业绩',
  1427. '等级内总业绩和',
  1428. '总业绩占比分红金额',
  1429. '分红佣金',
  1430. '分红复购金',
  1431. '分红状态',
  1432. '创建时间'
  1433. ], $arr, '合伙人分红明细'));
  1434. }
  1435. $query1 = clone($query);
  1436. $query2 = clone($query);
  1437. $query3 = clone($query);
  1438. // Primary, intermediate, advanced
  1439. $partner_profit_primary_part_money = $query1->where('w.user_group', '=', 4)->sum('part_money');
  1440. $partner_profit_primary_total_money = $query1->where('w.user_group', '=', 4)->sum('total_money');
  1441. $partner_profit_primary = bcadd($partner_profit_primary_part_money, $partner_profit_primary_total_money, 2);
  1442. $partner_profit_intermediate_part_money = $query2->where('w.user_group', '=', 5)->sum('part_money');
  1443. $partner_profit_intermediate_total_money = $query2->where('w.user_group', '=', 5)->sum('total_money');
  1444. $partner_profit_intermediate = bcadd($partner_profit_intermediate_part_money, $partner_profit_intermediate_total_money, 2);
  1445. $partner_profit_advanced_part_money = $query3->where('w.user_group', '=', 6)->sum('part_money');
  1446. $partner_profit_advanced_total_money = $query3->where('w.user_group', '=', 6)->sum('total_money');
  1447. $partner_profit_advanced = bcadd($partner_profit_advanced_part_money, $partner_profit_advanced_total_money, 2);
  1448. $data = $query->page($page)
  1449. ->limit($limit)
  1450. ->order('w.id desc')
  1451. ->select();
  1452. $count = $query->count();
  1453. if ($data) {
  1454. $data = $data->toArray();
  1455. foreach ($data as $k => $v) {
  1456. $data[$k]['radio'] = $v['radio'] == 2 ? '已发放' : '未发放';
  1457. }
  1458. }
  1459. $return_data['list'] = $data;
  1460. $return_data['count'] = $count;
  1461. $return_data['partner_profit_primary'] = $partner_profit_primary ?: 0.00;
  1462. $return_data['partner_profit_intermediate'] = $partner_profit_intermediate ?: 0.00;
  1463. $return_data['partner_profit_advanced'] = $partner_profit_advanced ?: 0.00;
  1464. return app('json')->success($return_data);
  1465. }
  1466. /**
  1467. * 获取联创奖励记录
  1468. * @return mixed
  1469. * @throws DataNotFoundException
  1470. * @throws DbException
  1471. * @throws ModelNotFoundException
  1472. */
  1473. public function getOriginatorList()
  1474. {
  1475. [$page, $limit] = $this->getPage();
  1476. $nickname = request()->param('nickname','');
  1477. $account = request()->param('account','');
  1478. $user_lianc_id = request()->param('user_lianc_id', '');
  1479. $dateRange = request()->param('dateRange', []);
  1480. $where = [];
  1481. if (!empty($dateRange)) {
  1482. $where[] = ['o.create_time', 'between', [strtotime($dateRange[0]), strtotime($dateRange[1])]];
  1483. }
  1484. if($nickname) $where[] = ['u.nickname','like','%'.$nickname.'%'];
  1485. if($account) $where[] = ['u.account','like','%'.$account.'%'];
  1486. if ($user_lianc_id) $where[] = ['o.user_lianc_id', '=', $user_lianc_id];
  1487. $query = Db::name('old_user_originator')->alias('o')
  1488. ->leftJoin('user u','o.user_id=u.uid')
  1489. ->leftJoin('old_user_lianc lianc','lianc.id=o.user_lianc_id')
  1490. ->field('o.*,u.uid,u.real_name,u.nickname,u.account,lianc.title, lianc.number')
  1491. ->where($where);
  1492. // 导出
  1493. $is_excel = request()->param('is_excel', 0);
  1494. if ($is_excel == 1) {
  1495. $data = $query->select();
  1496. $arr = [];
  1497. foreach ($data as $item) {
  1498. $arr[] = [
  1499. $item['id'],
  1500. $item['nickname'],
  1501. $item['account'],
  1502. $item['title'],
  1503. $item['number'],
  1504. $item['all_record'],
  1505. $item['all_amount'],
  1506. $item['money'],
  1507. date('Y-m-d H:i:s', $item['create_time'])
  1508. ];
  1509. }
  1510. return app('json')->success($this->getStatisticsExcel([
  1511. 'ID',
  1512. '用户昵称',
  1513. '用户账号(手机号)',
  1514. '联创等级',
  1515. '联创缴纳金额',
  1516. '本次联创分红总金额',
  1517. '当前等级分红总金额',
  1518. '获得分红金额',
  1519. '创建时间'
  1520. ], $arr, '联创分红明细'));
  1521. }
  1522. $query1 = clone($query);
  1523. $originator_dividend_payout_money = $query1->sum('money');
  1524. $data = $query->page($page)
  1525. ->limit($limit)
  1526. ->order('o.id desc')
  1527. ->select();
  1528. $count = $query->count();
  1529. if($data) {
  1530. $data = $data->toArray();
  1531. foreach ($data as $k=>$v){
  1532. $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
  1533. }
  1534. }
  1535. $return_data['list'] = $data;
  1536. $return_data['count'] = $count;
  1537. $return_data['originator_dividend_payout_money'] = $originator_dividend_payout_money;
  1538. return app('json')->success($return_data);
  1539. }
  1540. /**
  1541. * 获取股权分红记录
  1542. * @return mixed
  1543. * @throws DataNotFoundException
  1544. * @throws DbException
  1545. * @throws ModelNotFoundException
  1546. */
  1547. public function getStockList()
  1548. {
  1549. [$page, $limit] = $this->getPage();
  1550. $nickname = request()->param('nickname','');
  1551. $account = request()->param('account','');
  1552. $dateRange = request()->param('dateRange', []);
  1553. $where = [];
  1554. if (!empty($dateRange)) {
  1555. $where[] = ['o.create_time', 'between', [strtotime($dateRange[0]), strtotime($dateRange[1])]];
  1556. }
  1557. if($nickname) $where[] = ['u.nickname','like','%'.$nickname.'%'];
  1558. if($account) $where[] = ['u.account','like','%'.$account.'%'];
  1559. $query = Db::name('old_user_stock')->alias('o')
  1560. ->leftJoin('user u','o.user_id=u.uid')
  1561. ->field('o.*,u.uid,u.real_name,u.nickname,u.account')
  1562. ->where($where);
  1563. // 导出
  1564. $is_excel = request()->param('is_excel', 0);
  1565. if ($is_excel == 1) {
  1566. $data = $query->select();
  1567. $arr = [];
  1568. foreach ($data as $item) {
  1569. $arr[] = [
  1570. $item['id'],
  1571. $item['nickname'],
  1572. $item['account'],
  1573. $item['pack'],
  1574. $item['getcomm'],
  1575. $item['allgetcomm'],
  1576. date('Y-m-d H:i:s', $item['create_time']),
  1577. date('Y-m-d H:i:s', $item['update_time'])
  1578. ];
  1579. }
  1580. return app('json')->success($this->getStatisticsExcel([
  1581. 'ID',
  1582. '用户昵称',
  1583. '用户账号(手机号)',
  1584. '份数',
  1585. '本次佣金',
  1586. '累计佣金',
  1587. '创建时间',
  1588. '更新时间'
  1589. ], $arr, '股权分红明细'));
  1590. }
  1591. $query1 = clone($query);
  1592. $stock_getcomm = $query1->sum('getcomm');
  1593. $stock_allgetcomm = $query1->sum('allgetcomm');
  1594. $data = $query->page($page)
  1595. ->limit($limit)
  1596. ->order('o.id desc')
  1597. ->select();
  1598. $count = $query->count();
  1599. if($data) {
  1600. $data = $data->toArray();
  1601. foreach ($data as $k=>$v){
  1602. $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
  1603. $data[$k]['update_time'] = date('Y-m-d H:i:s',$v['update_time']);
  1604. }
  1605. }
  1606. $return_data['list'] = $data;
  1607. $return_data['count'] = $count;
  1608. $return_data['stock_getcomm'] = $stock_getcomm;
  1609. $return_data['stock_allgetcomm'] = $stock_allgetcomm;
  1610. return app('json')->success($return_data);
  1611. }
  1612. /**
  1613. * 股权分红创建表单
  1614. * @return mixed
  1615. */
  1616. public function stockCreateForm()
  1617. {
  1618. return app('json')->success(formToData($this->repository->stockCreateForm()));
  1619. }
  1620. /**
  1621. * @Author:Qinii
  1622. * @Date: 2020/5/11
  1623. * @param $id
  1624. * @return mixed
  1625. */
  1626. public function stockUpdateForm($id)
  1627. {
  1628. if (!$id) return app('json')->fail('数据不存在');
  1629. return app('json')->success(formToData($this->repository->stockUpdateForm($id)));
  1630. }
  1631. /**
  1632. * 添加
  1633. * @return mixed
  1634. * @throws DataNotFoundException
  1635. * @throws DbException
  1636. * @throws ModelNotFoundException
  1637. */
  1638. public function stockCreate()
  1639. {
  1640. $user_id = request()->param('user_id',0);
  1641. $pack = request()->param('pack',0);
  1642. if(!$user_id) return app('json')->fail('请选择用户');
  1643. if(!$pack) return app('json')->fail('请输入份数');
  1644. $user_data = Db::name('old_user_stock')->where('user_id',$user_id)->find();
  1645. if($user_data) return app('json')->fail('用户已存在');
  1646. $insert_data = [
  1647. 'user_id' => $user_id,
  1648. 'pack' => $pack,
  1649. 'getcomm' => 0,
  1650. 'allgetcomm' => 0,
  1651. 'create_time' => time(),
  1652. ];
  1653. Db::name('old_user_stock')->save($insert_data);
  1654. return app('json')->success('添加成功');
  1655. }
  1656. /**
  1657. * @Author:Qinii
  1658. * @Date: 2020/5/11
  1659. * @param $id
  1660. * @param validate $validate
  1661. * @return mixed
  1662. */
  1663. public function stockUpdate($id)
  1664. {
  1665. $pack = request()->param('pack',0);
  1666. if(!$pack) return app('json')->fail('请输入份数');
  1667. Db::name('old_user_stock')->where('id',$id)->update(['pack' => $pack,'update_time'=>time()]);
  1668. return app('json')->success('编辑成功');
  1669. }
  1670. /**
  1671. * @Author:Qinii
  1672. * @Date: 2020/5/11
  1673. * @param $id
  1674. * @return mixed
  1675. */
  1676. public function stockDelete($id)
  1677. {
  1678. if (!$id) return app('json')->fail('数据不存在');
  1679. Db::name('old_user_stock')->where('id',$id)->delete();
  1680. return app('json')->success('删除成功');
  1681. }
  1682. }