title = '商户列表'; $query = $this->_query($this->table); $query->equal('status')->dateBetween('create_at'); $query->like('name,phone,contacts,ip_white'); // 加载对应数据列表 $this->type = input('type', 'all'); $query->where(['is_deleted' => 0]); // 列表排序并显示 $query->order('status desc,id desc')->page(); } /** * 添加商户 * @auth true * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function add() { $this->_applyFormToken(); $this->_form($this->table, 'form'); } /** * 编辑商户 * @auth true * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function edit() { $this->_applyFormToken(); $this->_form($this->table, 'form'); } /** * 列表数据处理 * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ protected function _index_page_filter(array &$data) { $order = OrderService::instance(); foreach ($data as $k => $v) { $data[$k]['order_yes'] = $order->getOrderTotal($v['id'], 2); $data[$k]['order_no'] = $order->getOrderTotal($v['id'], 3); /* $where['mid'] = $v['id']; $where['account_type'] = 1; $where['type'] = 1; $data[$k]['account_chongzhi_total'] = sprintf("%.2f", $this->app->db->name('MerchantAccountLog')->where($where)->sum('num')); $where['account_type'] = 2; $where['type'] = 6; $xin = $this->app->db->name('MerchantAccountLog')->where($where)->find(); $data[$k]['credit_cash'] = 0.00; if ($xin) { $data[$k]['credit_total'] = sprintf("%.2f", $this->app->db->name('MerchantAccountLog')->where($where)->sum('num')); }*/ $data[$k]['account_surplus'] = $this->endsWithDoubleZero($data[$k]['account_surplus']); $data[$k]['credit_total'] = $this->endsWithDoubleZero($data[$k]['credit_total']); $data[$k]['account_total'] = $this->endsWithDoubleZero($data[$k]['account_total']); $data[$k]['account_baitiao'] = $this->endsWithDoubleZero($data[$k]['account_baitiao']); $data[$k]['account_consum'] = $this->endsWithDoubleZero($data[$k]['account_consum']); $data[$k]['credit_surplus'] = $this->endsWithDoubleZero($data[$k]['credit_surplus']); $data[$k]['credit_consum'] = $this->endsWithDoubleZero($data[$k]['credit_consum']); if ($data[$k]['credit_total'] > 0) { /* $where['mid'] = $v['id']; $where['account_type'] = 2; $where['type'] = 1; $result['credit_zonghuikuan'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num'); $where['type'] = 2; $result['credit_zonghuifu'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num'); $result['credit_zonghuikuan'] -= $result['credit_zonghuifu']; $where['type'] = 3; $result['credit_kou'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num'); $where['type'] = 4; $result['credit_huifu'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num'); $data[$k]['credit_huikuan'] = sprintf("%.2f", $result['credit_kou'] - $result['credit_huifu'] - $result['credit_zonghuikuan']); */ $data[$k]['credit_huikuan'] = $v['credit_total'] - $v['credit_surplus']; } else { $data[$k]['credit_huikuan'] = '0.00'; } if ($data[$k]['account_surplus'] < 0) { //$data[$k]['account_baitiao'] += $data[$k]['account_surplus']; //$data[$k]['account_surplus'] = 0; } } } public function endsWithDoubleZero($string) { // 获取字符串的长度 $length = strlen($string); // 检查字符串长度是否至少为4,并且最后两位是否为 '00' if ($length >= 4 && str_ends_with($string, '00')) { // 截去最后两位 if(str_ends_with($string, '.00')){ return $string; } return substr($string, 0, $length - 2); } // 如果最后两位不是 '00',返回原字符串 return $string; } /** * 表单数据处理 * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ protected function _form_filter(&$data) { $this->channel = $this->app->db->name('ChannelList')->where(['is_deleted' => 0])->order('sort desc,id desc')->select(); if ($this->request->isPost()) { if (isset($data['cids']) && $data['cids']) { $data['cids'] = implode(',', $data['cids']); } else { $data['cids'] = ''; } if (isset($data['id']) && $data['id'] > 0) { unset($data['username']); } else { if (empty($data['name'])) $this->error('商户名称不能为空!'); /* if (empty($data['username'])) $this->error('登陆账号不能为空!'); $where = ['username' => $data['username'], 'is_deleted' => 0]; if ($this->app->db->name($this->table)->where($where)->count() > 0) { $this->error("登陆账号{$data['username']}已经存在!"); } $data['password'] = md5($data['username']); */ } // print_r($data);die; } else { if (isset($data['cids']) && $data['cids'] && is_string($data['cids'])) { $data['cids'] = explode(',', $data['cids']); } else { $data['cids'] = array(); } } } protected function _form_result($id, $data) { $info = $this->app->db->name($this->table)->where(['id' => $id])->find(); if ($info && !$info['appid']) { $key = MerchantService::instance()->resetApi(1); $data = array( 'appid' => $key['appid'], 'appsecret' => $key['appsecret'], ); $this->app->db->name($this->table)->where(array('id' => $id))->update($data); } /* $where['id'] = $id; $info = $this->app->db->name($this->table)->where($where)->find(); MerchantService::instance()->get($info['appid'], false); */ } /** * 账户充值 * @auth true * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function recharge() { $this->_applyFormToken(); $mid = input('id'); $shouxin = MerchantLogService::instance()->checkShouxin($mid); if ($this->request->isGet()) { # 验证当前账户是否有授信 if ($shouxin) { $this->account_type = array('2'=>'授信账户', '1'=>'余额账户'); } else { $this->account_type = array('1'=>'余额账户', '2' => '授信账户'); } $this->verify = false; $this->_form($this->table, 'recharge'); } else { $data = $this->_vali([ 'account_type.require' => '账户类型不能为空!', 'mid.require' => '商户ID不能为空!', 'type.require' => '类型不能为空!', 'num.require' => '金额不能为空!', 'desc.require' => '描述不能为空!', ]); if ($data['account_type'] == 1 && $data['type'] == 6) { $this->error('无效操作,请选择授信账户!'); } if ($data['account_type'] == 1 && $data['type'] == -6) { $this->error('无效操作,请选择授信账户!'); } if ($data['account_type'] == 2 && $data['type'] == 1 && !$shouxin) { $this->error('无效操作,请先增加授信额度!'); } //$account = MerchantLogService::instance()->countAccount($data['type'], $data['num'], $data['mid'], $data['account_type']); //if ($data['type'] == 2 && $data['account_type'] == 1 && $data['num'] > $account['account_surplus']) $this->error('账户余额不足!'); if ($data['num'] < 1) $this->error('金额不能小于1元!'); if ($data['type'] == -6) { $data['type'] = 6; $data['num'] = $data['num'] * -1; } if (MerchantLogService::instance()->add($data['mid'], $data['num'], $data['account_type'],$data['type'],$data['desc']) !== false) { sysoplog('修改金额', '修改金额:'.$data['num'].'元,类型为:'. ($data['account_type'] =='1' ? '余额账户':'授信账户')); if(sysconf('queue') == 1){ #此处判断是否开启异步做消息提醒 try{ $redisService = RedisService::getInstance(); $redis_data =$data; $redis_data['time'] = date('Y-m-d H:i:s'); $redisService->push('merchant_recharge_msg', $redis_data); }catch (\Exception $e){ } } /* $info = MerchantService::instance()->getInfo($data['mid']); MerchantService::instance()->get($info['appid'], false); MerchantService::instance()->get($data['mid'], false); */ $this->success('操作成功!', ''); } else { $this->error('操作失败,请稍候再试!'); } } } /** * 重置商户秘钥 * @auth true * @throws \think\db\exception\DbException */ public function resetapi() { //$this->_applyFormToken(); if ($this->request->isPost()) { $key = MerchantService::instance()->resetApi(1); $data = $this->_vali([ 'id.require' => '商户ID不能为空!', 'appid' => $key['appid'], 'appsecret' => $key['appsecret'], ]); if (data_save($this->table, $data , 'id')) { # 重写缓存 MerchantService::instance()->get($key['appid'], false); MerchantService::instance()->get($data['id'], false); $this->success('秘钥重置成功,请通知商户使用新秘钥!', ''); } else { $this->error('秘钥重置失败,请稍候再试!'); } } $this->_save($this->table); } /** * 修改当前商户密码 * @login true * @auth true * @param integer $id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function pass($id = 0) { $this->_applyFormToken(); if ($this->app->request->isGet()) { $this->verify = false; $this->_form($this->table, 'pass', 'id', [], ['id' => $id]); } else { $data = $this->_vali([ 'username.require' => '登录用户账号不能为空!', 'password.require' => '登录密码不能为空!', 'repassword.require' => '重复密码不能为空!', //'oldpassword.require' => '旧的密码不能为空!', 'password.confirm:repassword' => '两次输入的密码不一致!', ]); $where = ['username' => $data['username'], 'is_deleted' => 0]; if ($this->app->db->name($this->table)->where($where)->whereRaw('id != ' . $id)->count() > 0) { $this->error("登陆账号{$data['username']}已经存在!"); } $user = $this->app->db->name($this->table)->where(['id' => $id])->find(); /* if (md5($data['oldpassword']) !== $user['password']) { $this->error('旧密码验证失败,请重新输入!'); } */ if (data_save($this->table, ['id' => $user['id'], 'username' => $data['username'], 'show_pwd' => $data['password'], 'password' => md5($data['password'])])) { $this->success('密码修改成功!', ''); } else { $this->error('密码修改失败,请稍候再试!'); } } } /** * 商户信息查看 * @login true * @auth true * @param integer $id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function info() { $this->_applyFormToken(); $id = input('id'); $this->host = sysconf('api_host'); $this->doc = sysconf('system_api_host'); $this->shanghu_host = sysconf('system_shanghu_host'); $this->_form($this->table, 'info', 'id', [], ['id' => $id]); } /** * 修改商户状态 * @auth true * @throws \think\db\exception\DbException */ public function state() { //$this->_applyFormToken(); $this->_save($this->table, $this->_vali([ 'status.in:0,1' => '状态值范围异常!', 'status.require' => '状态值不能为空!', ])); } /** * 修改商户其他状态码 * @auth true * @throws \think\db\exception\DbException */ public function otherstate() { //$this->_applyFormToken(); $this->_save($this->table, $this->_vali([ 'other_status.in:0,1' => '状态值范围异常!', 'other_status.require' => '状态值不能为空!', ])); } /** * 删除商户 * @auth true * @throws \think\db\exception\DbException */ public function remove() { $this->_applyFormToken(); $this->_delete($this->table); } /** * 修改ip白名单 * @login true * @auth true * @param integer $id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function ipWhite($id = 0) { if ($this->app->request->isGet()) { $this->_applyFormToken(); $this->verify = false; $this->_form($this->table, 'ipWhite','id', [], ['id' => $id]); } else { $id = input('id'); $ip_white = input('ip_white'); $up_ipWhite = MerchantService::instance()->update_ipWhite($id,$ip_white); if($up_ipWhite == '添加防火墙错误'){ $this->error('添加防火墙ip错误,请联系技术何时!'); }else{ $this->success('IP白名单修改成功!', ''); } } } /** * 修改自动发货机器人 * @login true * @auth true * @param integer $id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function autoCard($id = 0,$other_param='') { if ($this->app->request->isGet()) { $this->_applyFormToken(); $this->verify = false; $this->autoCardSoftware = 1; if($other_param && is_string($other_param)){ $other_param_arr = json_decode($other_param,true); if(is_array($other_param_arr) && isset($other_param_arr['autoCardSoftware'])){ $this->autoCardSoftware = $other_param_arr['autoCardSoftware']; $this->maSuDa_uid = $other_param_arr['maSuDa_uid']??null; $this->maSuDa_secret_key = $other_param_arr['maSuDa_secret_key']??null; } } $this->_form($this->table, 'autoCard','id', [], ['id' => $id]); } else { // var_dump(input());die; // array(12) { ["id"]=> string(2) "12" ["other_param"]=> string(113) "{"maSuDa_uid":"AAHamonFAOWtbFuvBodPfaUg","maSuDa_secret_key":"cmf9467r0xpwziym","autoCardSoftware":"3","ss":"11"}" ["spm"]=> string(10) "m-68-71-74" ["open_type"]=> string(5) "modal" ["autoCardSoftware"]=> string(1) "2" ["maSuDa_uid"]=> string(24) "AAHamonFAOWtbFuvBodPfaUg" ["maSuDa_secret_key"]=> string(16) "cmf9467r0xpwziym" ["maSuDa_message_config"]=> string(1) "1" ["maSuDa_trade_buyer_pay"]=> string(2) "on" ["maSuDa_trade_memo_modified"]=> string(2) "on" ["maSuDa_trade_status"]=> string(1) "1" ["maSuDa_afterSales_status"]=> string(1) "2" } // array(10) { ["id"]=> string(2) "12" ["other_param"]=> string(113) "{"maSuDa_uid":"AAHamonFAOWtbFuvBodPfaUg","maSuDa_secret_key":"cmf9467r0xpwziym","autoCardSoftware":"3","ss":"11"}" ["spm"]=> string(10) "m-68-71-74" ["open_type"]=> string(5) "modal" ["autoCardSoftware"]=> string(1) "2" ["maSuDa_uid"]=> string(24) "AAHamonFAOWtbFuvBodPfaUg" ["maSuDa_secret_key"]=> string(16) "cmf9467r0xpwziym" ["maSuDa_message_config"]=> string(1) "2" ["maSuDa_trade_status"]=> string(1) "2" ["maSuDa_afterSales_status"]=> string(1) "2" } $id = input('id'); $autoCardSoftware = input('autoCardSoftware'); $other_param_arr_new = [ 'autoCardSoftware'=>$autoCardSoftware ]; if($autoCardSoftware == 2){ if(!empty(input('maSuDa_uid'))){ $other_param_arr_new['maSuDa_uid'] = input('maSuDa_uid'); } if(!empty(input('maSuDa_secret_key'))){ $other_param_arr_new['maSuDa_secret_key'] = input('maSuDa_secret_key'); } #消息订阅关闭 if(!empty(input('maSuDa_message_config')) ){ $maSuDa_message_config = input('maSuDa_message_config'); $other_param_arr_new['maSuDa_message_config'] = $maSuDa_message_config; $maSuDa_message_config_array = []; // if(!empty(input('maSuDa_trade_buyer_pay') ) } if(!empty(input('maSuDa_afterSales_status')) ){ $other_param_arr_new['maSuDa_afterSales_status'] = input('maSuDa_afterSales_status');; } if(!empty(input('maSuDa_trade_status')) ){ $other_param_arr_new['maSuDa_trade_status'] = input('maSuDa_trade_status'); } } // var_dump($other_params);die; if($other_param && is_string($other_param)){ $other_param_arr = json_decode($other_param,true); if(is_array($other_param_arr)){ #合并数组 $other_param_arr_news = array_merge($other_param_arr,$other_param_arr_new); $other_param_arr_new = $other_param_arr_news; // $other_param_arr_new['autoCardSoftware'] = $autoCardSoftware; } } if (isset($maSuDa_message_config) && isset($other_param_arr_new['maSuDa_message_config'])){ #判断是否变化,进行消息修改 TODO } $other_json = json_encode($other_param_arr_new); $up = MerchantService::instance()->db()->where(array('id' => $id))->update(['other_param'=>$other_json]); // return $up; if(!$up){ $this->error('修改失败,请核查是否未变动!请联系技术处理!'); }else{ $this->success('自动发货软件修改成功!', ''); } } } }