223 lines
6.4 KiB
PHP
223 lines
6.4 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
|
|
namespace app\store\model;
|
|
|
|
use think\Session;
|
|
use app\common\model\Code as CodeModel;
|
|
use app\common\model\Shop as ShopModel;
|
|
use app\store\model\Order as OrderModel;
|
|
use think\facade\Cache;
|
|
|
|
/**
|
|
* 商家用户模型
|
|
* Class StoreUser
|
|
* @package app\store\model
|
|
*/
|
|
class Code extends CodeModel
|
|
{
|
|
|
|
/**
|
|
* 获取支付码列表
|
|
* @return \think\Paginator
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function getList($where)
|
|
{
|
|
return $this->where($where)
|
|
->field('*,FROM_UNIXTIME(create_time+expiration_time) as expiration_time')
|
|
->order(['create_time' => 'desc'])
|
|
->with(['shop','user'])
|
|
->paginate(15);
|
|
}
|
|
|
|
/**
|
|
* 新增记录
|
|
* @param $data
|
|
* @return bool|false|int
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function add($data)
|
|
{
|
|
if (empty($data['shop_id'])) {
|
|
$this->error = '请选择店铺';
|
|
return false;
|
|
}
|
|
if (empty($data['code_account'])) {
|
|
$this->error = '请填写产码账号';
|
|
return false;
|
|
}
|
|
if (empty($data['order_no'])) {
|
|
$this->error = '请填写订单号';
|
|
return false;
|
|
}
|
|
if (empty($data['passageway'])) {
|
|
$this->error = '请选择通道编号';
|
|
return false;
|
|
}
|
|
if (in_array($data['passageway'],['ZFBH5','SNZFBH5']) && empty($data['alipay'])) {
|
|
$this->error = '请填写支付宝链接';
|
|
return false;
|
|
}
|
|
if ($data['passageway'] == 'WX' && empty($data['link'])) {
|
|
$this->error = '请填写微信链接';
|
|
return false;
|
|
}
|
|
if (empty($data['money'])) {
|
|
$this->error = '请填写金额';
|
|
return false;
|
|
}
|
|
//判断微信产码数量是否超限
|
|
/*if($data['passageway'] == 'WX'){
|
|
$custNo = substr($data['link'],strripos($data['link'],"custNo=")+7,10);
|
|
$num = $this->where(
|
|
[
|
|
'passageway'=>'WX',
|
|
'link'=>['like','%'.$custNo.'%'],
|
|
])
|
|
->count();
|
|
if($num >= 8){
|
|
$this->error = '账号【'.$custNo.'】已达到产码上限8个';
|
|
return false;
|
|
}
|
|
}*/
|
|
if($data['passageway'] == 'ZFBH5'){
|
|
$data['link'] = $data['alipay'];
|
|
$searchUrl = $data['link'];
|
|
}else {
|
|
$otherPay = "https://order.suning.com/pay/otherPay.do?{{parameter}}&payChannel=PC";
|
|
$parameter = strstr($data['link'], 'orderId');
|
|
$searchUrl = str_replace("{{parameter}}", $parameter, $otherPay);
|
|
}
|
|
$data['search_url'] = $searchUrl;
|
|
$this->startTrans();
|
|
try {
|
|
//$shop = ShopModel::detail($data['shop_id']);
|
|
//$data['store_user_id'] = $shop['store_user_id'];
|
|
$data['store_id'] = self::$storeId;
|
|
$this->save($data);
|
|
$this->commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
$this->error = $e->getMessage();
|
|
$this->rollback();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新记录
|
|
* @param array $data
|
|
* @return bool
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function edit($data)
|
|
{
|
|
if (empty($data['shop_id'])) {
|
|
$this->error = '请选择店铺';
|
|
return false;
|
|
}
|
|
if (empty($data['code_account'])) {
|
|
$this->error = '请填写产码账号';
|
|
return false;
|
|
}
|
|
if (empty($data['order_no'])) {
|
|
$this->error = '请填写订单号';
|
|
return false;
|
|
}
|
|
if (empty($data['passageway'])) {
|
|
$this->error = '请选择通道编号';
|
|
return false;
|
|
}
|
|
if (in_array($data['passageway'],['ZFBH5','SNZFBH5']) && empty($data['alipay'])) {
|
|
$this->error = '请填写支付宝链接';
|
|
return false;
|
|
}
|
|
if ($data['passageway'] == 'WX' && empty($data['link'])) {
|
|
$this->error = '请填写微信链接';
|
|
return false;
|
|
}
|
|
if (empty($data['money'])) {
|
|
$this->error = '请填写金额';
|
|
return false;
|
|
}
|
|
if($data['passageway'] == 'ZFBH5'){
|
|
$data['link'] = $data['alipay'];
|
|
$searchUrl = $data['link'];
|
|
}else {
|
|
if($data['passageway'] == 'SNZFBH5')$data['link'] = $data['alipay'];
|
|
$otherPay = "https://order.suning.com/pay/otherPay.do?{{parameter}}&payChannel=PC";
|
|
$parameter = strstr($data['link'], 'orderId');
|
|
$searchUrl = str_replace("{{parameter}}", $parameter, $otherPay);
|
|
}
|
|
$data['search_url'] = $searchUrl;
|
|
$this->startTrans();
|
|
try {
|
|
//$shop = ShopModel::detail($data['shop_id']);
|
|
//$data['store_user_id'] = $shop['store_user_id'];
|
|
// 更新管理员记录
|
|
$this->save($data);
|
|
$this->commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
$this->error = $e->getMessage();
|
|
$this->rollback();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 软删除
|
|
* @return false|int
|
|
*/
|
|
public function setDelete()
|
|
{
|
|
return $this->delete();
|
|
}
|
|
/**
|
|
* 修改码的状态
|
|
* @param int $order_id
|
|
* @return false|int
|
|
*/
|
|
public function modifyUsed($order_id)
|
|
{
|
|
return $this->save([
|
|
'status' => 2,
|
|
'pay_status' => 1,
|
|
'order_id' => $order_id,
|
|
'allot_time' => time(),
|
|
]);
|
|
}
|
|
/**
|
|
* 切换状态
|
|
* @param $status
|
|
* @return false|int
|
|
*/
|
|
public function changeStatus($status)
|
|
{
|
|
if($this['pay_status'] == 2){
|
|
return '当前已是已核销状态';
|
|
}
|
|
if($bool = $this->save(['pay_status' => $status])){
|
|
$bool = true;
|
|
}
|
|
return $bool;
|
|
}
|
|
/**
|
|
* 切换启停状态
|
|
* @param $state
|
|
* @return false|int
|
|
*/
|
|
public function stateSwitch($state)
|
|
{
|
|
if(!in_array($state,[1,2])){
|
|
return '未知状态';
|
|
}
|
|
if($bool = $this->save(['state' => $state])){
|
|
$bool = true;
|
|
}
|
|
return $bool;
|
|
}
|
|
}
|