$params['category_id'], 'type_id' => $params['type_id'] ?? '', 'mer_name' => $params['mer_name'], 'credit_buy' => $params['credit_buy'] ?? 0, 'settle_cycle' => $params['settle_cycle'] ?? 15, 'interest_rate' => $params['interest_rate'] ?? 0, 'province_id' => $params['province_id'] ?? '', 'city_id' => $params['city_id'] ?? '', 'area_id' => $params['area_id'] ?? '', 'street_id' => $params['street_id'] ?? '', 'village_id' => $params['village_id'] ?? '', 'mer_address' => $params['mer_address'] ?? '', 'mer_avatar' => $params['mer_avatar'] ?? '', 'mark' => $params['mark'] ?? '', 'sort' => $params['sort'] ?? 99, 'status' => $params['status'] ?? 0, 'commission_rate' => $params['commission_rate'] ?? '', 'commission_switch' => $params['commission_switch'] ?? '', 'long' => $params['long'] ?? '', 'lat' => $params['lat'] ?? '', 'service_phone' => $params['phone'], 'financial_bank' => $params['financial_bank'] ?? '', 'financial_wechat' => $params['financial_wechat'] ?? '', 'financial_alipay' => $params['financial_alipay'] ?? '', 'financial_type' => $params['financial_type'] ?? '', 'data_json' => json_encode([ 'company_address' => $params['address'] ?? '', 'company_nickname' => $params['company_nickname'] ?? '', 'social_credit_code' => $params['social_credit_code'] ?? '', 'company_name' => $params['company_name'] ?? '', 'images' => $params['images'][0] ?? '', ]) ]); Db::name('user_auth_shop')->insert(['pid' => $res->id, 'user_id' => 0, 'shop_uid' => $params['shop_user_id'], 'status' => 0, 'type' => 1, 'create_time' => time(), 'jg_register_id' => $params['jg_register_id']]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑商户列表 * @param array $params * @return bool * @author likeadmin * @date 2024/04/23 16:35 */ public static function edit(array $params): bool { Db::startTrans(); try { Merchant::where('mer_id', $params['mer_id'])->update([ 'category_id' => $params['category_id'], 'type_id' => $params['type_id'] ?? '', 'mer_name' => $params['mer_name'], 'credit_buy' => $params['credit_buy'] ?? 0, 'settle_cycle' => $params['settle_cycle'] ?? 15, 'interest_rate' => $params['interest_rate'] ?? 0, 'province_id' => $params['province_id'] ?? '', 'city_id' => $params['city_id'] ?? '', 'area_id' => $params['area_id'] ?? '', 'street_id' => $params['street_id'] ?? '', 'village_id' => $params['village_id'] ?? '', 'mer_address' => $params['mer_address'], 'mer_avatar' => $params['mer_avatar'] ?? '', 'mark' => $params['mark'] ?? '', 'sort' => $params['sort'] ?? 99, 'status' => $params['status'] ?? 0, 'commission_rate' => $params['commission_rate'] ?? '', 'commission_switch' => $params['commission_switch'] ?? '', 'long' => $params['long'] ?? '', 'lat' => $params['lat'] ?? '', 'service_phone' => $params['phone'], 'financial_bank' => $params['financial_bank'] ?? '', 'financial_wechat' => $params['financial_wechat'] ?? '', 'financial_alipay' => $params['financial_alipay'] ?? '', 'financial_type' => $params['financial_type'] ?? '', 'data_json' => json_encode([ 'company_address' => $params['address'] ?? '', 'company_nickname' => $params['company_nickname'] ?? '', 'social_credit_code' => $params['social_credit_code'] ?? '', 'company_name' => $params['company_name'] ?? '', 'images' => $params['images'][0] ?? '', ]) ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 审核商户状态 * @param array $params * @return bool * @author likeadmin * @date 2024/04/23 16:35 */ public static function status(array $params): bool { $apply_info = Db::name('user_auth_shop')->where('id', $params['apply_id'])->findOrEmpty(); Db::startTrans(); try { if ($params['status'] == 1) { $user = [ 'real_name' => $params['service_phone'], 'nickname' => '用户' . $params['service_phone'], 'account' => $params['service_phone'], 'mobile' => $params['service_phone'], 'password' => $params['service_phone'], 'sex' => 0, 'is_disable' => 0, 'user_money' => 0 ]; $res1 = UserLogic::add($user); if ($res1 == false) { Db::rollback(); self::setError(UserLogic::getError()); return false; } $data = [ 'user_id' => $res1['id'], 'status' => 1, 'apply_status' => 1, 'pid' => $params['mer_id'] ]; Merchant::where('mer_id', $params['mer_id'])->update(['status' => 1, 'uid' => $res1['id']]); Db::name('user_auth_shop')->where('id', $params['apply_id'])->update($data); } if ($params['status'] == 0) { $data = [ 'mark' => $params['mark'] ?? '', 'apply_status' => -1 ]; Merchant::where('mer_id', $params['mer_id'])->update([ 'status' => 0, ]); Db::name('user_auth_shop')->where('id', $params['apply_id'])->update($data); } if (!empty($apply_info['jg_register_id'])) { $res=(new JgPushService())->sendMsg($apply_info['jg_register_id'], '您的经销入驻请求审核' . ($params['status'] == 1 ? '通过' : '被拒绝'), '/pages/bindDistribution/index'); if($res!==true){ Db::rollback(); self::setError('极光推送失败:'.$res); return false; } } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 修改密码 */ public static function editPassword($params) { Db::startTrans(); try { // $admin_id=Db::name('user_auth_shop')->where(['type'=>2,'pid'=>$params['id']])->value('admin_id'); // if($admin_id){ // $passwordSalt = Config::get('project.unique_identification'); // $password=create_password($params['password'], $passwordSalt); // Admin::where('id',$admin_id)->update(['password'=>$password]); // } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 设置余额 */ public static function set_money($id, $set_money, $type = 1) { Db::startTrans(); try { if ($type == 1) { Merchant::where('mer_id', $id)->inc('mer_money', $set_money)->update(); $record = [ 'financial_record_sn' => time(), 'order_id' => 0, 'number_sn' => getNewOrderId('XTCZ'), 'user_id' => 0, 'financial_type' => OrderEnum::SYSTEM_SET, 'financial_pm' => OrderEnum::INCOME, 'number' => $set_money, 'status' => 1, 'type' => OrderEnum::MERCHANT, 'mer_id' => $id, ]; FinancialRecord::create($record); } else { $money = Merchant::where('mer_id', $id)->value('mer_money'); if ($money < $set_money) { Db::rollback(); self::setError('余额不足'); return false; } Merchant::where('mer_id', $id)->dec('mer_money', $set_money)->update(); $record = [ 'financial_record_sn' => time(), 'order_id' => 0, 'number_sn' => getNewOrderId('XTJS'), 'user_id' => 0, 'financial_type' => OrderEnum::SYSTEM_SET, 'financial_pm' => OrderEnum::EXPENDITURE, 'number' => $set_money, 'status' => 1, 'type' => OrderEnum::MERCHANT, 'mer_id' => $id, ]; FinancialRecord::create($record); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 商户绑定商品 * @param array $params * @return bool * @author likeadmin * @date 2024/04/23 16:35 */ public static function bindGoods(array $params): bool { Db::startTrans(); try { foreach ($params['bind_data'] as $v) { $data = [ 'mer_id' => $params['mer_id'], 'goods_id' => $v['goods_id'], 'nums' => $v['nums']??0 ]; $has = Db::name('merchant_bind_goods')->where('mer_id', $params['mer_id'])->where('goods_id', $v['goods_id'])->findOrEmpty(); if (!empty($has)) { Db::name('merchant_bind_goods')->where('id', $has['id'])->update($data); } else { Db::name('merchant_bind_goods')->insert($data); } } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 商户绑定银行卡 * @param array $params * @return bool * @date 2024/04/23 16:35 */ public static function bind_bank(array $params): bool { $merchant = Merchant::where('mer_id', $params['mer_id'])->findOrEmpty(); $user=User::where('id',$merchant['uid'])->field('real_name','mobile')->find(); if (!$merchant) { self::setError('商户不存在'); return false; } if(!$user){ self::setError('没有绑定用户'); return false; } if ($params['is_own'] == 0) { $info = [ 'name' => $params['name'], 'idNum' => $params['id_card'], 'cardNo' => $params['bank_code'], 'mobile' => $user['mobile'], ]; $thinkApi = new ThinkApi(); $result = $thinkApi->request('bankcard/auth', $info); if ($result['code'] != 0 || empty($result['data'])) { self::setError($result['message']); return false; } //认证结果。01:一致 02:不一致 03:认证不确定 04:认证失败。01、02收费 if ($result['data']['result'] == 4 || $result['data']['result'] == 2) { self::setError('认证失败,请检查姓名,身份证,银行卡,银行预留手机号码是否正确'); return false; } } Db::startTrans(); try { $save_data = [ 'mer_id' => $params['mer_id'], 'name' => $params['name'], 'bank_id' => $params['bank_id'], 'bank_code' => $params['bank_code'], 'bank_branch' => $params['bank_branch'], 'phone' => $user['mobile'], 'id_card' => $params['id_card'] ?? '', 'financial_img' => $params['financial_img'], 'is_own' => $params['is_own'], 'is_check' => 1, 'create_time' => time() ]; //写入数据 (new MerchantBank)->save($save_data); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除商户列表 * @param array $params * @return bool * @author likeadmin * @date 2024/04/23 16:35 */ public static function delete(array $params): bool { return Merchant::destroy($params['mer_id']); } /** * @notes 获取商户列表详情 * @param $params * @return array * @author likeadmin * @date 2024/04/23 16:35 */ public static function detail($params): array { $data = Merchant::where('mer_id', $params['mer_id'])->findOrEmpty(); $province = Db::name('geo_province')->field('province_name')->where('province_code', $data['province_id'])->findOrEmpty(); $city = Db::name('geo_city')->field('city_name')->where('city_code', $data['city_id'])->findOrEmpty(); $area = Db::name('geo_area')->field('area_name')->where('area_code', $data['area_id'])->findOrEmpty(); $street = Db::name('geo_street')->field('street_name')->where('street_code', $data['street_id'])->findOrEmpty(); $village = Db::name('geo_village')->field('village_name')->where('village_code', $data['village_id'])->findOrEmpty(); $data['province_name'] = !empty($province) ? $province['province_name'] : ''; $data['city_name'] = !empty($city) ? $city['city_name'] : ''; $data['area_name'] = !empty($area) ? $area['area_name'] : ''; $data['street_name'] = !empty($street) ? $street['street_name'] : ''; $data['village_name'] = !empty($village) ? $village['village_name'] : ''; return $data->toArray(); } }