| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020-05-07
- *
- *
- */
- namespace app\controller\admin\user;
- use app\common\model\merchant\order\OrderMerchant;
- use app\common\model\system\admin\Admin;
- use app\common\model\system\auth\Role;
- use app\common\model\user\UserCertification;
- use app\common\repositories\merchant\order\OrderMerchantRepository;
- use app\common\repositories\user\UserExtractRepository;
- use app\controller\api\merchant\sxy\Access;
- use app\controller\api\user\Im;
- use crmeb\basic\BaseController;
- use app\common\repositories\store\coupon\StoreCouponUserRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\common\repositories\user\UserBillRepository;
- use app\common\repositories\user\UserGroupRepository;
- use app\common\repositories\user\UserLabelRepository;
- use app\common\repositories\user\UserRepository;
- use app\common\repositories\wechat\WechatNewsRepository;
- use app\common\repositories\wechat\WechatUserRepository;
- use app\validate\admin\UserNowMoneyValidate;
- use app\validate\admin\UserValidate;
- use FormBuilder\Exception\FormBuilderException;
- use think\App;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Exception;
- use think\facade\Cache;
- use think\facade\Db;
- use think\Log;
- /**
- * Class User
- * @package app\controller\admin\user
- * @author xaboy
- * @day 2020-05-07
- */
- class User extends BaseController
- {
- /**
- * @var UserRepository
- */
- protected $repository;
- /**
- * User constructor.
- * @param App $app
- * @param UserRepository $repository
- */
- public function __construct(App $app, UserRepository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- }
- /**
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-07
- */
- public function lst()
- {
- /*
- * 昵称,分组,标签,地址,性别,
- */
- $where = $this->request->params([
- 'label_id',
- 'user_type',
- 'sex',
- 'is_promoter',
- 'country',
- 'pay_count',
- 'user_time_type',
- 'user_time',
- 'nickname',
- 'province',
- 'city',
- 'group_id',
- 'identity',
- 'now_money',
- 'account',
- 'user_card',
- 'user_rich_type',
- 'stockholder',
- 'subIdentify',
- 'user_group',
- 'is_show'
- ]);
- [$page, $limit] = $this->getPage();
- return app('json')->success($this->repository->getList($where, $page, $limit));
- }
- /**
- * 协议
- * @return mixed
- */
- public function xieyi(){
- var_dump(111);die;
- return app('json')->success($this->repository->getXieYi());
- }
- /**
- * 批量设置星级
- * @return mixed
- * @throws DbException
- */
- public function start_level(){
- $ids = (array)$this->request->param('ids', []);
- $admin_start_level = $this->request->param('admin_start_level', '0');
- if (!count($ids))
- return app('json')->fail('数据不存在');
- foreach ($ids as $id){
- $rich=Db::name('user_rich')->where('uid',$id)->count();
- if($rich){
- Db::name('user_rich')->where('uid',$id)->update(['admin_start_level'=>$admin_start_level]);
- }else{
- $insert=['uid' => $id, 'admin_start_level' => $admin_start_level];
- Db::name('user_rich')->insert($insert);
- }
- }
- return app('json')->success('修改成功');
- }
- public function spreadList($uid)
- {
- $where = $this->request->params(['level', 'keyword', 'date','identity']);
- [$page, $limit] = $this->getPage();
- return app('json')->success($this->repository->getLevelList($uid, $where, $page, $limit));
- }
- public function spreadOrder($uid)
- {
- $where = $this->request->params(['level', 'keyword', 'date']);
- [$page, $limit] = $this->getPage();
- return app('json')->success($this->repository->subOrder($uid, $page, $limit, $where));
- }
- public function clearSpread($uid)
- {
- $this->repository->update($uid, ['spread_uid' => 0]);
- return app('json')->success('清除成功');
- }
- /**
- * @param $id
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws FormBuilderException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-09
- */
- public function updateForm($id)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->userForm($id)));
- }
- public function get_info($id)
- {
- // ini_set('display_errors','On');
- //
- // error_reporting(E_ALL);
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- $user=Db::name('user')->find($id);
- $certification = Db::name('user_certification')->where("uid", $id)->find();
- $user['real_name'] = $certification['user_name'] ?? '';
- $user['card_id'] = $certification['user_card'] ?? '';
- $user_rich=Db::name('user_rich')->where('uid',$id)->find();
- $user['admin_start_level'] =$user_rich?$user_rich['admin_start_level']:'0';
- $user['user_rich_type'] =$user_rich?$user_rich['type']:'0';
- $user['area_manage_pics'] =[];
- $user['area_manage_obtain'] ='0';
- if($user_rich){
- $user['area_manage_obtain'] =$user_rich['obtain'];
- if($user_rich['pics']){
- $user['area_manage_pics']=explode(',',$user_rich['pics']);
- }
- }
- $code_list_province=DB::name('user')->where('user_group',6)->where('manage_address!=""')->column('manage_address');
- $code_list_district=DB::name('user')->where('user_group',5)->where('manage_address!=""')->column('manage_address');
- // 省
- $code_list_province_arr=[];
- foreach ($code_list_province as $v){
- $v_explode=explode(',',$v);
- $code_list_province_arr[$v_explode[0]][]=$v_explode[0];
- }
- //区县
- $code_list_district_arr=[];
- foreach ($code_list_district as $v){
- $v_explode=explode(',',$v);
- $code_list_district_arr[$v_explode[1]][]=$v_explode[0];
- }
- if( $user['manage_address']){
- $code_list_explode=explode(',',$user['manage_address']);
- }
- $regions1 = Db::name('regions') -> field('id as value,name as label')->where('level',1) ->select();
- $regions2 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',2) ->select();
- $regions3 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',3) ->select();
- $regions3_data=[];
- foreach ($regions3 as $v){
- $v['disabled']=false;
- if(isset($code_list_district_arr[$v['pid']]) && in_array($v['value'],$code_list_district_arr[$v['pid']])){
- if(!isset($code_list_explode[2]) || $code_list_explode[2]!=$v['value']){
- $v['disabled']=true;
- }
- }
- $regions3_data[$v['pid']][]=$v;
- }
- $regions2_data=[];
- foreach ($regions2 as $v){
- $v['children']=isset( $regions3_data[$v['value']])? $regions3_data[$v['value']]:[];
- $regions2_data[$v['pid']][]=$v;
- }
- $city_area=[];
- foreach ($regions1 as $v){
- $v['children']=isset( $regions2_data[$v['value']])? $regions2_data[$v['value']]:[];
- $city_area[]=$v;
- }
- $regions2_data2=[];
- foreach ($regions2 as $v){
- $v['disabled']=false;
- if(isset($code_list_province_arr[$v['pid']]) && in_array($v['value'],$code_list_province_arr[$v['pid']])){
- if(!isset($code_list_explode[0]) || $code_list_explode[0]!=$v['value']){
- $v['disabled']=true;
- }
- }
- $regions2_data2[$v['pid']][]=$v;
- }
- $city_area_2=[];
- foreach ($regions1 as $v){
- $v['children']=isset( $regions2_data2[$v['value']])? $regions2_data2[$v['value']]:[];
- $city_area_2[]=$v;
- }
- $user['city_area_1']=$city_area;
- $user['city_area_2']=$city_area_2;
- //查询当前团队的用户列表
- $sql = "select getUserSpreadId($id) as uids";
- //\think\facade\Log::info("lplpDB".$sql);
- try{
- $spread_user_list = Db::query($sql);
- }catch (Exception $exception){
- return app('json')->success($exception);
- }
- $spread_user_list = array_diff(explode(",", trim($spread_user_list[0]['uids'],'$,')), [$id]);
- //查询创客手机号
- $marker_phone_list = [];
- $marker_user_list = Db::name("user")->whereIn("uid", $spread_user_list)->where('is_shop_partner', 1)->select()->toArray();
- foreach ($marker_user_list as $k=>$v){
- $marker_phone_list[] = $v['account'];
- }
- $user['marker_phone_list'] = $marker_phone_list;
- return app('json')->success($user);
- }
- /**
- * @param $id
- * @param UserValidate $validate
- * @param UserLabelRepository $labelRepository
- * @param UserGroupRepository $groupRepository
- * @return mixed
- * @throws DbException
- * @author xaboy
- * @day 2020-05-09
- */
- public function update($id, UserValidate $validate, UserLabelRepository $labelRepository, UserGroupRepository $groupRepository)
- {
- $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', []]]);
- $validate->check($data);
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- // if ($data['group_id'] && !$groupRepository->exists($data['group_id']))
- // return app('json')->fail('分组不存在');
- $label_id = (array)$data['label_id'];
- $maker_phone_list = (array)$data['maker_phone_list'] ?? [];
- foreach ($label_id as $k => $value) {
- $label_id[$k] = (int)$value;
- if (!$labelRepository->exists((int)$value))
- return app('json')->fail('标签不存在');
- }
- //查询当前团队的用户列表,判断当前用户是否为团队成员
- $sql = "select getUserSpreadId($id) as uids";
- $spread_user_list = Db::query($sql);
- $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
- $error_maker_phone = [
- 'no_registry' => [],
- 'no_team' => [],
- ];
- foreach ($maker_phone_list as $k => $maker_phone) {
- //检查手机号是否已注册
- $user = Db::name('user')->where('account', $maker_phone)->find();
- if (empty($user)) {
- $error_maker_phone['not_sign'][] = $maker_phone;
- }
- if (!in_array($user['uid'], explode(",", $spread_user_list))) {
- $error_maker_phone['no_team'][] = $maker_phone;
- }
- }
- if (count($error_maker_phone['no_registry']) > 0 || count($error_maker_phone['no_team']) > 0) {
- return app('json')->fail("创客手机号校验异常", [
- 'error_maker_phone' => $error_maker_phone,
- ]);
- } else {
- foreach ($maker_phone_list as $k => $maker_phone) {
- Db::name('user')
- ->where('account', $maker_phone)
- ->update([
- 'is_shop_partner' => 1,
- ]);
- }
- }
- unset($data['maker_phone_list']);
- $data['label_id'] = implode(',', $label_id);
- if(!$data['birthday']) unset($data['birthday']);
- $user_group=input('post.user_group','');
- if(in_array($user_group,[5,6])){
- $city_list=input('post.city',[]);
- $city_string = implode(",", $city_list);
- if(!$city_list){
- return app('json')->fail('请选择代理区域');
- }
- $code_list_count=Db::name('user')->where('manage_address', $city_string)->where('uid !='.$id)->count();
- if($code_list_count){
- return app('json')->fail('改区域已经分配给其他人了');
- }
- $data['manage_address']=$city_string;
- $data['up_agency_time']=date('Y-m-d H:i:s');
- }else{
- $data['up_agency_time']=null;
- }
- if ($user_group == 3) {
- $mer = Db::name('merchant')->where('uid', $id)->find();
- if ($mer)
- return app('json')->fail('已经是创客,不可调整成大V经理身份');
- $data['up_vip_time'] = date('Y-m-d H:i:s');
- } else {
- $data['up_vip_time'] = null;
- }
- if ($user_group == 4) {
- $new_user_group = Db::name('user')->where('uid', $id)->value('user_group');
- if ($new_user_group == 3)
- return app('json')->fail('已经是大V经理,不可调整成创客身份');
- $data['up_vip_time'] = date('Y-m-d H:i:s');
- } else {
- $data['up_vip_time'] = null;
- }
- $this->repository->update($id, $data);
- //更新身份证信息
- $cardData = [];
- if ($data['card_id']) {
- $cardData['user_card'] = $data['card_id'];
- }
- if ($data['real_name']) {
- $cardData['user_name'] = $data['real_name'];
- }
- if (!empty($cardData)) {
- Db::name('user_certification')->where("uid", $id)->update($cardData);
- }
- // $admin_start_level=input('post.admin_start_level',0);
- // if (!empty($admin_start_level)) {
- // }
- $pics=input('post.area_manage_pics',[]);
- $user_rich_ypdate['type']=input('post.user_rich_type',0);
- $user_rich_ypdate['obtain']=input('post.area_manage_obtain',0);
- $user_rich_ypdate['admin_start_level']=input('post.admin_start_level',0);
- if($pics){
- $user_rich_ypdate['pics']=implode(',',$pics);
- }
- $rich=Db::name('user_rich')->where('uid',$id)->count();
- if($rich){
- Db::name('user_rich')->where('uid',$id)->update($user_rich_ypdate);
- }else{
- $user_rich_ypdate['uid']=$id;
- Db::name('user_rich')->insert($user_rich_ypdate);
- }
- return app('json')->success('编辑成功');
- }
- public function maker_check_phone($id)
- {
- $params = $this->request->params(['phone']);
- $user = Db::name('user')->where('account', $params['phone'])->find();
- if (empty($user)) {
- return app('json')->fail('该用户未注册,请先邀请用户注册~');
- }
- //查询当前团队的用户列表,判断当前用户是否为团队成员
- $sql = "select getUserSpreadId($id) as uids";
- $spread_user_list = Db::query($sql);
- $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
- if (!in_array($user['uid'], explode(",", $spread_user_list))) {
- return app('json')->fail('该用户不属于您团队,不可设置为合伙人~');
- }
- return app('json')->success();
- }
- /**
- * 设为合伙人
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function setAreaManage()
- {
- $area_type = $this->request->param('area_type', 0);//类型 district town village
- $area_manage_address_ids = $this->request->param('area_manage_address_ids', 0);//
- $uid = $this->request->param('uid', 0);//用户id
- // $area_manage = Db::name('area_manage')->where('code_list', $area_manage_address_ids)->find();
- // if ($area_manage) {
- // return app('json')->fail('该地区已有代理!');
- // }
- // $area_manage = Db::name('area_manage')->where('uid', $uid)->find();
- // if ($area_manage) {
- // return app('json')->fail('该用户已经是代理了!');
- // }
- $area_manage_address_list = explode(',', $area_manage_address_ids);
- switch ($area_type) {
- case 'district':
- if (count($area_manage_address_list) != 3)
- return app('json')->fail('请输入正确的高级合伙人代理地址!');
- break;
- case 'town':
- if (count($area_manage_address_list) != 4)
- return app('json')->fail('请输入正确的中级合伙人代理地址!');
- break;
- case 'village':
- if (count($area_manage_address_list) != 3)
- return app('json')->fail('请输入正确的初级合伙人代理地址!');
- break;
- default :
- return app('json')->fail('请输入正确的初级合伙人代理地址!');
- }
- $end_address = Db::name('regions_new')->where('id', end($area_manage_address_list))->find();
- if (empty($end_address))
- return app('json')->fail('该地址不存在!');
- // 查询当时是否已有未支付的合伙人商品订单
- $hehuo_store_group_order = DB::name('store_order')
- ->alias('store_order')
- ->leftJoin('store_order_product store_order_product', 'store_order.order_id=store_order_product.order_id')
- ->where('store_order.uid', $uid)
- ->where('store_order.paid', 0)
- ->where('store_order_product.type', 'in', [11, 12, 13])
- ->find();
- if($hehuo_store_group_order)
- return app('json')->fail('该用户当前有待支付的合伙人商品,不可下单!');
- $key = 'area_manage_order:' . $area_manage_address_ids;
- $redis = Cache::store('redis')->handler();
- if (!$redis->setnx($key, 1))
- return app('json')->fail('该地区已有用户锁定,请稍后再试!');
- // 区域设置成功 记录
- Db::name('area_manage')->insert([
- 'uid' => $uid,
- 'type' => $area_type,
- 'order_sn' => '',
- 'code_list' => $area_manage_address_ids,
- 'create_time' => date('Y-m-d H:i:s')
- ]);
- Db::name('log')->insert(['data' => "后台修改{$uid}为{$area_type}区域成功,code_list:{$area_manage_address_ids}!"]);
- return app('json')->success('修改成功');
- }
- /**
- * 设为回填
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function setHuiTian()
- {
- $uid = $this->request->param('uid', 0);//用户id
- $user_rich = Db::name('user_rich')->where('uid', $uid)->find();
- if ($user_rich) {
- if ($user_rich['is_huitian'] == 1)
- return app('json')->fail('该用户已经是回填!');
- if ($user_rich['type'] != 0)
- return app('json')->fail('只有普通用户可以设置为回填!');
- Db::name('user_rich')->where('uid', $uid)->update([
- 'type' => 4,
- 'is_huitian' => 1,
- ]);
- } else {
- Db::name('user_rich')->where('uid', $uid)->insert([
- 'uid' => $uid,
- 'type' => 4,
- 'is_huitian' => 1,
- ]);
- }
- Db::name('log')->insert(['data' => "后台修改{$uid}为回填成功!"]);
- return app('json')->success('修改成功');
- }
- /**
- * @param $id
- * @param UserLabelRepository $labelRepository
- * @return mixed
- * @throws DbException
- * @author xaboy
- * @day 2020-05-08
- */
- public function changeLabel($id, UserLabelRepository $labelRepository)
- {
- $label_id = (array)$this->request->param('label_id', []);
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- foreach ($label_id as $k => $value) {
- $label_id[$k] = (int)$value;
- if (!$labelRepository->exists((int)$value))
- return app('json')->fail('标签不存在');
- }
- $label_id = implode(',', $label_id);
- $this->repository->update($id, compact('label_id'));
- return app('json')->success('修改成功');
- }
- /**
- * @param UserLabelRepository $labelRepository
- * @return mixed
- * @throws DbException
- * @author xaboy
- * @day 2020-05-08
- */
- public function batchChangeLabel(UserLabelRepository $labelRepository)
- {
- $label_id = (array)$this->request->param('label_id', []);
- $ids = (array)$this->request->param('ids', []);
- if (!count($ids))
- return app('json')->fail('数据不存在');
- foreach ($label_id as $k => $value) {
- $label_id[$k] = (int)$value;
- if (!$labelRepository->exists((int)$value))
- return app('json')->fail('标签不存在');
- }
- $this->repository->batchChangeLabelId($ids, $label_id);
- return app('json')->success('修改成功');
- }
- /**
- * @param $id
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws FormBuilderException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-08
- */
- public function changeLabelForm($id)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->changeLabelForm($id)));
- }
- /**
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws FormBuilderException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-08
- */
- public function batchChangeLabelForm()
- {
- $ids = $this->request->param('ids', '');
- $ids = array_filter(explode(',', $ids));
- if (!count($ids))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->changeLabelForm($ids)));
- }
- /**
- * 批量微信入账公证处
- * @return mixed
- * @author php迷途小书童
- * @created 2021/3/10 15:37
- */
- public function batchGzc()
- {
- $ids = $this->request->param('ids', '');
- $type = $this->request->param('type', '');
- $ids = array_filter(explode(',', $ids));
- if (!count($ids))
- return app('json')->fail('数据不存在');
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- foreach ($ids as $id) {
- $user = $this->repository->get($id);
- switch ($type) {
- case 'WX':
- if (!$user->wechat_user_id)
- return app('json')->fail('账号:'.$user->account.'暂未微信授权,操作停止');
- $pay_user_id = $user->wechat_user_id;
- break;
- case 'ALI':
- if (!$user->ali_user_id)
- return app('json')->fail('账号:'.$user->account.'暂未支付宝授权,操作停止');
- $pay_user_id = $user->ali_user_id;
- break;
- default:
- return app('json')->fail('请求参数错误');
- break;
- }
- $count = OrderMerchant::getDB()
- ->where('pay_user_id', $pay_user_id)
- ->where('paid', 1)
- ->where('gzc', 0)
- ->count();
- if (!$count)
- return app('json')->fail('账号:'.$user->account.'暂无要发起的入账信息,操作停止');
- $certification = UserCertification::getDB()
- ->where('uid', $user->uid)
- ->find();
- if (!$certification)
- return app('json')->fail('账号:'.$user->account.'暂未实名认证,操作停止');
- $OrderMerchantRepository->batchGzc($certification,$user,$type);
- }
- return app('json')->success('发起成功');
- }
- /**
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws FormBuilderException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-08
- */
- public function batchChangeGroupForm()
- {
- $ids = $this->request->param('ids', '');
- $ids = array_filter(explode(',', $ids));
- if (!count($ids))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->changeGroupForm($ids)));
- }
- /**
- * @param $id
- * @param UserGroupRepository $groupRepository
- * @return mixed
- * @throws DbException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeGroup($id, UserGroupRepository $groupRepository)
- {
- $group_id = (int)$this->request->param('group_id', 0);
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- if ($group_id && !$groupRepository->exists($group_id))
- return app('json')->fail('分组不存在');
- $this->repository->update($id, compact('group_id'));
- return app('json')->success('修改成功');
- }
- /**
- * @param UserGroupRepository $groupRepository
- * @return mixed
- * @throws DbException
- * @author xaboy
- * @day 2020-05-07
- */
- public function batchChangeGroup(UserGroupRepository $groupRepository)
- {
- $group_id = (int)$this->request->param('group_id', 0);
- $ids = (array)$this->request->param('ids', []);
- if (!count($ids))
- return app('json')->fail('数据不存在');
- if ($group_id && !$groupRepository->exists($group_id))
- return app('json')->fail('分组不存在');
- $this->repository->batchChangeGroupId($ids, $group_id);
- return app('json')->success('修改成功');
- }
- /**
- * @param $id
- * @return mixed
- * @throws FormBuilderException
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeGroupForm($id)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->changeGroupForm($id)));
- }
- /**
- * @param $id
- * @return mixed
- * @throws FormBuilderException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeNowMoneyForm($id)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->changeNowMoneyForm($id)));
- }
- /**
- * @param $id
- * @param UserNowMoneyValidate $validate
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeNowMoney($id, UserNowMoneyValidate $validate)
- {
- $data = $this->request->params(['now_money', 'type']);
- $validate->check($data);
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- $this->repository->changeNowMoney($id, $this->request->adminId(), $data['type'], $data['now_money']);
- return app('json')->success('修改成功');
- }
- /**
- * @param $id
- * @return mixed
- * @throws FormBuilderException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeProForm($id)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->changeProForm($id)));
- }
- /*
- * 更改用户推荐信息
- * cabbage
- * 2020-11-04
- * */
- public function changePro($id,UserRepository $repository)
- {
- $spread_account = $this->request->param('spread_account');
- if (!$spread_account || !$id){
- return app('json')->fail('参数丢失');
- }
- if($repository->update_spread($id,$spread_account)){
- return app('json')->success("修改成功");
- }else{
- return app('json')->fail("失败");
- }
- }
- /**
- * @param $id
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws FormBuilderException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-08
- */
- public function changePassForm($id)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- return app('json')->success(formToData($this->repository->changePassForm($id)));
- }
- /*
- * 更改用户密码
- * cabbage
- * 2021-2-23
- * */
- public function changePass($id,UserRepository $repository)
- {
- $pass_word = $this->request->param('pass_word');
- if (!$pass_word || !$id){
- return app('json')->fail('参数丢失');
- }
- if($repository->changePass($id,$pass_word)){
- return app('json')->success("修改成功");
- }else{
- return app('json')->fail("失败");
- }
- }
- /**
- * @param WechatNewsRepository $wechatNewsRepository
- * @param WechatUserRepository $wechatUserRepository
- * @return mixed
- * @author xaboy
- * @day 2020-05-11
- */
- public function sendNews(WechatNewsRepository $wechatNewsRepository, WechatUserRepository $wechatUserRepository)
- {
- $ids = array_filter(array_unique(explode(',', $this->request->param('ids'))));
- $news_id = (int)$this->request->param('news_id', 0);
- if (!$news_id)
- return app('json')->fail('请选择图文消息');
- if (!$wechatNewsRepository->exists($news_id))
- return app('json')->fail('数据不存在');
- if (!count($ids))
- return app('json')->fail('请选择微信用户');
- $wechatUserRepository->sendNews($news_id, $ids);
- return app('json')->success('发送成功');
- }
- // public function promoterList()
- // {
- // $where = $this->request->params(['keyword', 'user_type', 'status', 'sex', 'group_id']);
- //// $where['is_promoter'] = 1;
- // [$page, $limit] = $this->getPage();
- // return app('json')->success($this->repository->getList($where, $page, $limit));
- // }
- public function promoterList()
- {
- $where = $this->request->params(['keyword']);
- // $where['is_promoter'] = 1;
- [$page, $limit] = $this->getPage();
- return app('json')->success($this->repository->getAgent($where, $page, $limit));
- }
- public function promoterAgent()
- {
- $where = $this->request->params(['keyword', 'identity']);
- // $where['is_promoter'] = 1;
- [$page, $limit] = $this->getPage();
- return app('json')->success($this->repository->getAgentList($where, $page, $limit));
- }
- public function getPromoter($id)
- {
- // $where = $this->request->params(['id']);
- $where['id'] =$id;
- // [$page, $limit] = $this->getPage();s
- return app('json')->success($this->repository->getonePromoter($where));
- }
- public function updateAgent($id)
- {
- $where = $this->request->params(["status"]);
- $res = $this->repository->updateAgent($where,$id);
- if($res['code'] == 400){
- return app('json')->fail($res['msg']);
- }
- return app('json')->success("审核成功");
- }
- /*线下支付*/
- public function xianPay($id){
- $mark = input("mark");
- $res = $this->repository->xianPayAgent($id,$mark);
- if($res['code'] == 400){
- return app('json')->fail($res['msg']);
- }
- return app('json')->success("线下支付成功");
- }
- public function detail($id)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- $data = $this->repository->userOrderDetail($id);
- $data['enterprise_user'] = null;
- $where=["uid"=>$id,"type"=>"commission","commission_type"=>5];
- $ylj=Db::name("user_bill")->where($where)->whereIn('status',[0,1])->sum('number');
- $data['ylj']=$ylj?$ylj:0;
- return app('json')->success($data);
- }
- public function order($id, StoreOrderRepository $repository)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- [$page, $limit] = $this->getPage();
- return app('json')->success($repository->userList($id, $page, $limit));
- }
- public function coupon($id, StoreCouponUserRepository $repository)
- {
- if (!$this->repository->exists($id))
- return app('json')->fail('数据不存在');
- [$page, $limit] = $this->getPage();
- return app('json')->success($repository->userList($id, $page, $limit));
- }
- public function bill($id, UserBillRepository $repository)
- {
- if (!$this->repository->exists(intval($id)))
- return app('json')->fail('数据不存在');
- [$page, $limit] = $this->getPage();
- return app('json')->success($repository->userList([
- 'now_money' => 0,
- 'status' => 1
- ], $id, $page, $limit));
- }
- /**
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function new_bill($id, UserBillRepository $billRepository)
- {
- [$page, $limit] = $this->getPage();
- $where = [
- // 'now_money' => $this->request->param('type', 0),
- 'status' => $this->request->param('status'),
- // 'mer_id' => $this->request->merId()
- 'not_commission_type' => [5, 7, 17, 19],
- ];
- if ($this->request->param('is_red') == true) {
- $where['is_red_brokerage'] = 1;
- }
- $bill_list = $billRepository->userList($where, $id, $page, $limit);
- foreach ($bill_list['list'] as $key => $item) {
- if ($item['status'] == 1) $bill_list['list'][$key]['jiesuan_string'] = "已结算";
- if ($item['status'] == 0) $bill_list['list'][$key]['jiesuan_string'] = "未结算";
- if ($item['status'] == -1) $bill_list['list'][$key]['jiesuan_string'] = "已失效";
- }
- return app('json')->success($bill_list);
- }
- /*
- * 用户养老金信息
- * @author cabbage
- * @date 2020-11-03
- * */
- public function annuity($id, UserRepository $repository)
- {
- if (!$this->repository->exists(intval($id)))
- return app('json')->fail('数据不存在');
- return app('json')->success($repository->get_yanglao($id));
- }
- /**
- * 养老金明细
- */
- public function annuitylog($id, UserRepository $repository){
- [$page, $limit] = $this->getPage();
- $where=["uid"=>$id,"type"=>"commission","commission_type"=>5];
- $res = $repository->yanglaolog($where,$page,$limit);
- return app('json')->success($res);
- }
- /*用户银行卡信息*/
- public function getAccount($id){
- $where['user_id']=$id;
- $data = app()->make(UserExtractRepository::class)->list($where);
- return app('json')->success($data);
- }
- /*设置用户身份*/
- /*
- * pay:1-付费。2-未付费
- * type:3-银卡。4-金卡。5-商户。6-渠道商
- * */
- public function setIdentity(){
- $data = $this->request->params(["uid","pay","type","dc_id","recommend_phone"]);
- $dc_id = $data['dc_id'];
- if(empty($data['uid'])){
- return app('json')->fail('参数错误');
- }
- $time = date('Y-m-d', time());
- $time = strtotime($time);
- $end_time = $time + 31536000 - 1;
- $recommend = Db::name('user') -> where('account',$data['recommend_phone']) -> value('uid');
- $storeOrderRepository = app()->make(StoreOrderRepository::class);
- $access = new Access();
- //付费
- if($data['pay'] == 1){
- switch ($data['type']){
- case 3:
- case 4:
- if($data['type'] == 3){
- $order['pay_price'] = '399';
- }else{
- $order['pay_price'] = '999';
- }
- $order['uid'] = $data['uid'];
- $order['order_id'] = 0;
- $order['order_sn'] = 'sIO'.$storeOrderRepository->getNewOrderId();
- $order['mer_id'] = 0;
- $order['dacang_id'] = $dc_id;
- if($data['type'] == 3){
- $storeOrderRepository -> dacang_yin($order,0);
- }elseif($data['type'] == 4){
- $storeOrderRepository -> dacang($order,0);
- }
- break;
- case 5:
- //赠送商户
- $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
- if(!$merchant)
- Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'status'=>3,'activation_code'=>rand('000000000','999999999')]);
- $mer = Db::name('user_mer') -> where('uid',$data['uid']) -> find();
- if(!$mer){
- Db::name('user_mer') -> insert(['uid'=>$data['uid'],'mer'=>2]);
- }else{
- Db::name('user_mer') -> where('uid',$data['uid'])->inc('mer', 2) ->update();
- }
- $order_sn = 'sIM'.$storeOrderRepository->getNewOrderId();
- $insertData=[
- 'mer_id'=>0,
- 'pay_price'=>systemConfig("annual"),
- 'status'=>1,
- 'order_no'=>$order_sn,
- 'uid'=>$data['uid']
- ];
- $id = Db::name('merchant_annual_cost_order')->insertGetId($insertData);
- $access->nianfei_yj($id);
- break;
- case 6:
- //赠送返本商户
- $mer = Db::name('user_mer') -> where('uid',$data['uid']) -> find();
- if(!$mer){
- Db::name('user_mer') -> insert(['uid'=>$data['uid'],'mer'=>10]);
- }else{
- Db::name('user_mer') -> where('uid',$data['uid'])->inc('mer', 10) ->update();;
- }
- //赠送商户
- $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
- if(!$merchant)
- Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'activation_code'=>rand('000000000','999999999')]);
- //赠送大仓会员资格
- $dacang_user = Db::name('da_cang_user')->where('uid', $data['uid'])->find();
- $dc_id = 1;
- //如果不是金卡会员,赠送金卡会员一年
- if (!$dacang_user) {
- Db::name('da_cang_user')->insert(['uid' => $data['uid'], 'ctime' => time(), 'end_time' => $end_time, 'dc_id' => $dc_id,'status'=>1,'type'=>1]);
- }else{
- //如果是银卡会员,变成金卡,一年 || 是否已过期,如果已过期,赠送金卡会员一年
- if($dacang_user['type'] == 2 || $dacang_user['end_time'] < $time){
- Db::name('da_cang_user')->where('uid', $data['uid'])->where('dc_id', $dc_id)->update(['end_time' => $end_time,'status'=>1,'type'=>1]);
- }
- }
- $order_sn = 'sIC'.$storeOrderRepository->getNewOrderId();
- $insertData=[
- 'pay_price'=>systemConfig("channel_price"),
- 'status'=>1,
- 'order_no'=>$order_sn,
- 'uid'=>$data['uid']
- ];
- Db::name('channel_order')->insertGetId($insertData);
- //渠道商
- $channel_user=Db::name('channel_user')->where('uid',$data['uid']) -> find();
- if($channel_user){
- Db::name('channel_user')->where('uid',$data['uid'])->update(['status'=>1]);
- }else{
- Db::name('channel_user')->insert(['uid'=>$data['uid'],'status'=>1,'ctime'=>time(),'recommend_uid'=>$recommend]);
- }
- $access->channel_fenyong($order_sn);
- break;
- }
- return app('json')->success('付费身份设置成功');
- }else{
- //未付费
- switch ($data['type']){
- case 3:
- case 4:
- $dacang_user = Db::name('da_cang_user')->where('uid', $data['uid'])->find();
- $type = $data['type'] == 3 ? 2 : 1;
- //如果原来有大仓会员。修改
- if ($dacang_user) {
- Db::name('da_cang_user')->where('uid', $data['uid'])->where('dc_id', $dc_id)->update(['end_time' => $end_time,'status'=>1,'type'=>$type]);
- } else {
- //新会员
- Db::name('da_cang_user')->insert(['uid' => $data['uid'], 'ctime' => time(), 'end_time' => $end_time, 'dc_id' => $dc_id,'status'=>1,'type'=>$type]);
- }
- break;
- case 5:
- //赠送商户
- $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
- if(!$merchant)
- Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'status'=>3,'activation_code'=>rand('000000000','999999999')]);
- break;
- case 6:
- //渠道商
- $channel_user=Db::name('channel_user')->where('uid',$data['uid']) -> find();
- if($channel_user){
- Db::name('channel_user')->where('uid',$data['uid'])->update(['status'=>1]);
- }else{
- Db::name('channel_user')->insert(['uid'=>$data['uid'],'status'=>1,'ctime'=>time(),'recommend_uid'=>$recommend]);
- }
- }
- return app('json')->success('未付费身份设置成功');
- }
- }
- public function gongfu_user(){
- $data = $this->request->params(["uid","red","type"]);
- if(empty($data['uid']) || empty($data['type'])){
- return app('json')->fail('参数错误');
- }
- $type = $data['type'];
- $red = $data['red'];
- $uid = $data['uid'];
- $check = Db::name('user_rich')->where('uid',$uid)->find();
- if($check){
- $update['type'] = $type;
- Db::name('user_rich')->where('uid',$uid)->update($update);
- }else{
- Db::name('user_rich')->insert(['uid' => $uid, 'type' => $type]);
- }
- if ($red > 0){
- Db::name('user_rich')->where('uid',$uid)->inc('red', $red)->update();
- Db::name('user_rich_log')->insert([
- 'uid' => $uid,
- 'red' => $red,
- 'pm' => 1,
- 'time' => time(),
- 'order_id' => 0,
- 'mark' => '系统赠送红积分'
- ]);
- }
- return app('json')->success('身份设置成功');
- }
- public function bangfu(){
- $data = $this->request->params(["uid"]);
- if(empty($data['uid'])){
- return app('json')->fail('参数错误');
- }
- $uid = $data['uid'];
- $check = Db::name('user_bangfu') -> where('uid', $uid) -> find();
- if (!$check){
- Db::name('user_bangfu')->insert([
- 'uid' => $uid,
- 'time' => time(),
- 'status' => 1
- ]);
- }
- return app('json')->success('身份设置成功');
- }
- public function bangfu_list(){
- [$page, $limit] = $this->getPage();
- $list = Db::name('user_bangfu')
- -> alias('ub')
- -> join('user u', 'u.uid = ub.uid')
- -> leftJoin('user_rich ur', 'ub.uid = ur.uid')
- -> field('u.nickname,u.account,ub.status,ur.type,ub.id as uid')
- -> page($page, $limit)
- -> select();
- return app('json')->success($list);
- }
- public function bangfu_examine(){
- $data = $this->request->params(["uid","status"]);
- if(empty($data['uid'])){
- return app('json')->fail('参数错误');
- }
- $uid = $data['uid'];
- $check = Db::name('user_bangfu') -> where('id', $uid) -> find();
- if (!$check){
- return app('json')->fail('不存在');
- }
- $save = Db::name('user_bangfu') -> where('uid', $uid) -> update(['status'=>$data['status']]);
- if ($save){
- return app('json')->success('修改成功');
- }
- return app('json')->fail('出错');
- }
- public function importExcel()
- {
- $file = request()->file('file');
- if(!$file){
- return app('json')->fail('请上传文件');
- }
- $extension = pathinfo($file->getOriginalName(), PATHINFO_EXTENSION);
- if ($extension != 'xlsx' && $extension != 'xls') {
- return app('json')->fail('请上传xlx或xlsx文件');
- }
- // 创建一个新的Excel读取器对象
- $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
- $objPHPExcel = $objReader->load($file);
- // 选择活动工作表
- $objPHPExcel->setActiveSheetIndex(0);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- // 循环遍历行和列
- $yonghu=[];
- foreach ($sheetData as $k=>$row) {
- if($k==1){
- continue;
- }
- if($row['A'] && $row['A']!=NULL && $row['A']!=''){
- $yonghu[]=array('a'=>$row['A'],'b'=>$row['B']);
- }
- }
- if(count($yonghu)<1){
- return app('json')->fail('未获取到数据');
- }
- $repository = app()->make(UserRepository::class);
- foreach ($yonghu as $k=>$v){
- $user = $repository->accountByUser($v['a']);
- if ($user){
- // return app('json')->fail('手机号已存在');
- $yonghu[$k]['user'] = $user;
- }else{
- $yonghu[$k]['user'] = $repository->registr($v['a'],'A123456','APP',0);
- }
- }
- foreach ($yonghu as $v){
- $user=$v['user'];
- $spread_uid=$v['user']['spread_uid'];
- if($v['b'] && $v['b']!=null && $v['b']!=''){
- $pid=Db::name('user')->where('account',$v['b'])->value('uid');
- if($pid){
- $repository->bindSpread($user, intval($pid));
- $spread_uid=$pid;
- }
- }
- $mer_count=Db::name('merchant')->where('uid',$user['uid'])->count();
- if(!$mer_count){
- // $code_insert['uid']=$v['uid'];
- // $code_insert['code']=time().'_'.$this->generateRandomCode(20);
- // $code_insert['ctime']=time();
- // $code_insert['type']=2;
- // $re=Db::name('activation_code')->insertGetId($code_insert);
- $mer_insert['uid']=$user['uid'];
- $mer_insert['spread_uid']=$spread_uid;
- $mer_id=Db::name('merchant')->insertGetId($mer_insert);
- $merchant_admin_insert['mer_id']=$mer_id;
- $merchant_admin_insert['uid']= $user['uid'];
- $merchant_admin_insert['account']= $user['account'];
- $merchant_admin_insert['real_name']= $user['account'];
- $merchant_admin_insert['phone']= $user['account'];
- $merchant_admin_insert['level']= 0;
- $re=Db::name('merchant_admin')->insertGetId($merchant_admin_insert);
- $merchant_intention['mer_id']=$mer_id;
- $merchant_intention['uid']= $user['uid'];
- $merchant_intention['phone']= $user['account'];
- Db::name('merchant_intention')->insertGetId($merchant_intention);
- // insert into rrx_merchant_admin(mer_id,uid,account,pwd,phone,real_name,level) values (#{mer_id},#{uid},#{account},#{pwd},#{phone},#{real_name},#{level})
- }
- }
- return app('json')->success('导入成功');
- }
- public function getImAdmin(){
- try {
- $data = json_decode('{
- "im_pass": 873947,
- "im_user_id": "admin",
- "im_uuid": "53d0f370-f104-11ee-8cd6-45641584429c"
- }',true);
- return app('json')->success($data);
- $im = new Im();
- $data = [];
- $data['im_pass'] = mt_rand(100000,999999);
- $data['im_user_id'] = 'admin';
- $data['im_uuid']= $im->createImUser('useradmin', 'admin',$data['im_pass']);
- return app('json')->success($data);
- } catch (\Exception $e) {
- Db::name('log')->insert(['data'=>'注册异常'.$e->getFile().$e->getMessage().$e->getLine()]);
- }
- return app('json')->fail('注册失败');
- }
- public function enterpriseUserScoreApi(){
- [$page, $limit] = $this->getPage();
- $where = $this->request->params(['uid']);
- $list=Db::name('user_sign_score')->where($where)->page($page, $limit)->order('id desc')->select();
- foreach ($list as $k=>$v){
- $v['pm_text']='收入';
- if($v['pm']==2 || $v['pm']==4){
- $v['pm_text']='支出';
- $v['reward_socre']='-'.$v['reward_socre'];
- }else{
- $v['pm_text']='收入';
- $v['reward_socre']='+'.$v['reward_socre'];
- }
- if($v['order_id'] && empty($v['order_sn'])){
- $v['order_sn']=Db::name('store_order')->where('order_id',$v['order_id'])->value('order_sn');
- }
- if(empty($v['order_sn'])){
- $v['order_sn']='--';
- }
- $v['create_time'] = $v['settlement_time'];
- $v['create_time'] = date("Y-m-d H:i:s", $v['addtime']);
- $list[$k]=$v;
- }
- $data['list']=$list;
- $data['count']=Db::name('user_sign_score')->where($where)->count();
- return app('json')->success($data);
- }
- }
|