|
|
@@ -7,11 +7,8 @@ use app\common\enum\PayEnum;
|
|
|
use app\common\enum\WorkEnum;
|
|
|
use app\common\logic\BaseLogic;
|
|
|
use app\common\model\dict\DictData;
|
|
|
-use app\common\model\effective\EffectiveCategory;
|
|
|
-use app\common\model\effective\EffectiveRules;
|
|
|
use app\common\model\goods\Goods;
|
|
|
use app\common\model\master_worker\MasterWorker;
|
|
|
-use app\common\model\orders\OrderEffectiveLog;
|
|
|
use app\common\model\orders\RechargeOrder;
|
|
|
use app\common\model\performance\PerformanceRules;
|
|
|
use app\common\model\recharge\OrderGoods;
|
|
|
@@ -61,8 +58,8 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
//生成服务工单
|
|
|
$work_data = [
|
|
|
'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
|
|
|
- 'real_name' => !empty($params['user_info']['real_name'])?$params['user_info']['real_name']:$params['user_info']['nickname'],
|
|
|
- 'mobile' => $params['user_info']['mobile'],
|
|
|
+ 'real_name' => $params['contact_people'],
|
|
|
+ 'mobile' => $params['contact_number'],
|
|
|
'address' => $params['address'],
|
|
|
'title' => $goods->goods_name . '*' . $goods->goods_number.$goods->good_unit,
|
|
|
'category_type' => $goods['category_type'],
|
|
|
@@ -326,6 +323,7 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
|
|
|
public static function queryEffective($params)
|
|
|
{
|
|
|
+ Db::startTrans();
|
|
|
try {
|
|
|
$work_id = \app\common\model\recharge\RechargeOrder::where([
|
|
|
'order_type' => 0,
|
|
|
@@ -335,91 +333,9 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
if(empty($work_id)){
|
|
|
throw new Exception('订单不存在');
|
|
|
}
|
|
|
- //查询工单下所有已完结的订单
|
|
|
- $orders = RechargeOrder::with('orderGoods')->where(['sn'=>$params['sn'],
|
|
|
- 'user_id'=>$params['user_id'],
|
|
|
- 'pay_status'=>1])->select()->toArray();
|
|
|
- //查询订单领取的保修卡
|
|
|
- $logs = OrderEffectiveLog::where(['sn'=>$params['sn'],'user_id'=>$params['user_id']])->select();
|
|
|
- $data = [];
|
|
|
- $queryData = [];
|
|
|
- foreach($orders as $oV){
|
|
|
- foreach($oV['orderGoods'] as $v){
|
|
|
- if($logs->where('sn',$oV['sn'])->where('goods_id',$v['goods_id'])->count() > 0){
|
|
|
- $logData = $logs->where('sn',$oV['sn'])->where('goods_id',$v['goods_id'])->toArray();
|
|
|
- foreach($logData as $k =>$lV){
|
|
|
- $logData[$k]['end_effective_time'] = date("Y-m-d H:i:s",$lV['end_effective_time']);
|
|
|
- $logData[$k]['is_receive'] = 1;
|
|
|
- }
|
|
|
- $data = array_merge($data,$logData);
|
|
|
- continue;
|
|
|
- }
|
|
|
- $queryData[] = ['work_id'=>$oV['work_id'],'sn' =>$oV['sn'],'goods_id' => $v['goods_id'],'goods_category_id' => $v['goods_category_id'],'pay_time'=>$oV['pay_time'] ?? $oV['update_time']];
|
|
|
- }
|
|
|
- }
|
|
|
- $categoryIds = array_column($queryData,'goods_category_id');
|
|
|
- if(!empty($categoryIds)){
|
|
|
- $effectiveRule = EffectiveCategory::with('effectiveRule')->whereIn('goods_category_id',$categoryIds)->select();
|
|
|
- foreach($queryData as $v){
|
|
|
- if(!$effectiveRule->where('goods_category_id',$v['goods_category_id'])->isEmpty()){
|
|
|
- $val = $v ;
|
|
|
- $result = $effectiveRule->where('goods_category_id',$v['goods_category_id'])->toArray()[0];
|
|
|
- $val = $val+[
|
|
|
- 'id' => 0,
|
|
|
- 'effective_id'=>$result['effectiveRule']['id'],
|
|
|
- 'user_id'=>$params['user_id'],
|
|
|
- 'effective_unit'=>$result['effectiveRule']['effective_unit'],
|
|
|
- 'effective_num'=>$result['effectiveRule']['effective_num'],
|
|
|
- 'remark'=>$result['effectiveRule']['remark'],
|
|
|
- 'is_receive' => 0,
|
|
|
- 'end_effective_time'=> date("Y-m-d H:i:s",EffectiveRules::formatEndEffectiveTime($val['pay_time'],$result['effectiveRule']['effective_num'],$result['effectiveRule']['effective_unit'])),
|
|
|
- 'create_time'=> date("Y-m-d H:i:s",time()),
|
|
|
- 'update_time'=> date("Y-m-d H:i:s",time()),
|
|
|
- ];
|
|
|
- $data[] = $val;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return $data;
|
|
|
- }catch(\Exception $e){
|
|
|
- self::setError($e->getMessage());
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function receiveEffective($params)
|
|
|
- {
|
|
|
- try{
|
|
|
- $orderGoods = OrderGoods::where(['sn'=>$params['sn'],'goods_id' => $params['goods_id']])->findOrEmpty();
|
|
|
- if($orderGoods->isEmpty()){
|
|
|
- throw new \Exception('订单不存在');
|
|
|
- }
|
|
|
- $log = OrderEffectiveLog::where(['sn'=>$params['sn'],'user_id'=>$params['user_id'],'goods_id' =>$params['goods_id'] ])->findOrEmpty();
|
|
|
- if($log->isEmpty()){
|
|
|
- $orderInfo = \app\common\model\recharge\RechargeOrder::where([
|
|
|
- 'order_type' => 0,
|
|
|
- 'user_id' => $params['user_id'],
|
|
|
- 'sn'=>$params['sn'],
|
|
|
- 'pay_status'=>1
|
|
|
- ])->findOrEmpty();
|
|
|
- if(empty($orderInfo)){
|
|
|
- throw new Exception('订单不存在');
|
|
|
- }
|
|
|
- $effective = EffectiveCategory::with('effectiveRule')->where('goods_category_id',$orderGoods->goods_category_id)->findOrEmpty();
|
|
|
- OrderEffectiveLog::create([
|
|
|
- 'effective_id' => $effective->effectiveRule->id,
|
|
|
- 'sn' => $params['sn'],
|
|
|
- 'user_id' => $params['user_id'],
|
|
|
- 'work_id' => $orderInfo->work_id,
|
|
|
- 'goods_id' => $orderGoods->goods_id,
|
|
|
- 'effective_unit' => $effective->effectiveRule->effective_unit,
|
|
|
- 'effective_num' => $effective->effectiveRule->effective_num,
|
|
|
- 'remark' => $effective->effectiveRule->remark,
|
|
|
- 'end_effective_time' => EffectiveRules::formatEndEffectiveTime($orderInfo->pay_time?? $orderInfo->update_time ,$effective->effectiveRule->effective_num,$effective->effectiveRule->effective_unit),
|
|
|
- ]);
|
|
|
- }
|
|
|
return true;
|
|
|
}catch(\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
self::setError($e->getMessage());
|
|
|
return false;
|
|
|
}
|