ソースを参照

【Add】增加产品排序,增加订单查询条件,修复取消订单缺陷

liuxiangxin 7 ヶ月 前
コミット
45a36d0a33

+ 7 - 1
app/Http/Controllers/Admin/Orders.php

@@ -37,6 +37,7 @@ class Orders extends Auth{
 		// 接受参数
 		$code					= request('order_code','');
 		$productCode			= request('product_code','');
+		$phone					= request('phone','');
 		$customCode				= request('custom_code','');
 		$productName			= request('product_name','');
 		$status					= request('status',0);
@@ -53,6 +54,7 @@ class Orders extends Auth{
 		if( $uid )				$map[] = ['custom.uid','=',$uid];
 		if( $productId )		$map[] = ['orders_product.product_id','=',$productId];
 		if( $productName )		$map[] = ['orders_product.product_name','=',$productName];
+		if( $phone )			$map[] = ['orders_addr.contact_phone','=',$phone];
 		if( $startTime )		$map[] = ['orders_product.insert_time','>=',strtotime($startTime)];
 		if( $endTime )			$map[] = ['orders_product.insert_time','<=',strtotime($endTime)];
 		if( $status )			$map[] = ['orders_product.status','=',$status];
@@ -88,7 +90,7 @@ class Orders extends Auth{
 	 * 状态
 	 * 
 	 * */
-	public function set_status( Request $request, Model $Model){
+	public function set_status( Request $request, Model $Model,OrdersProduct $OrdersProduct){
 		// 验证参数
 		$request->scene('set_status')->validate();
 		// 接收参数
@@ -102,6 +104,10 @@ class Orders extends Auth{
 		$result			= $Model->edit($id,['status'=>$status]);
 		// 提示新增失败
 		if( !$result )	return json_send(['code'=>'error','msg'=>'设置失败']);
+		// 查询数据
+		$result			= $OrdersProduct->query()->where([['order_id','=',$id]])->update(['status'=>$status,'update_time'=>time()]);
+		// 提示新增失败
+		if( !$result )	return json_send(['code'=>'error','msg'=>'设置失败']);
 		// 记录行为
 		$this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],['status'=>$status]);
 		// 告知结果

+ 21 - 1
app/Http/Controllers/Admin/Product.php

@@ -49,7 +49,7 @@ class Product extends Auth{
 		if( $startTime )		$map[] = ['insert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
 		if( !is_null($status) )	$map[] = ['status','=',$status];
 		// 查询数据
-		$list					= $Model->query()->where($map)->orderByDesc('id')->paginate(request('limit',config('page_num',10)))->appends(request()->all());
+		$list					= $Model->query()->where($map)->orderBy('sort')->paginate(request('limit',config('page_num',10)))->appends(request()->all());
 		// 循环处理数据
 		foreach ($list as $key => $value) {
 			// id转编号
@@ -541,4 +541,24 @@ class Product extends Auth{
 		return					$this->brush($last,$arr); # 递归处理, 直到$arr滚到最后一组属性
 	}
 
+	/**
+	 * 排序
+	 * 
+	 * */
+	public function set_sort( Request $request, Model $Model ){
+		// 验证参数
+		$request->scene('set_sort')->validate();
+		// 接收参数
+		$id				= request('id',0);
+		$sort			= request('sort',0);
+		// 查询数据
+		$result			= $Model->edit($id,['sort'=>$sort]);
+		// 提示新增失败
+		if( !$result )	return json_send(['code'=>'error','msg'=>'设置失败']);
+		// 记录行为
+		$this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],['sort'=>$sort]);
+		// 告知结果
+		return			json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
+	}
+
 }

+ 2 - 1
app/Http/Controllers/Api/Product.php

@@ -50,7 +50,8 @@ class Product extends Api{
 										->where($map)
 										->whereIn('product_city.city_id',$wherIn)
 										->groupBy('product_id')
-										->paginate($limit,['product.id','product.name','product.thumb','product.spec','product.price','product.market_price','product.stock']);
+										->orderBy('sort')
+										->paginate($limit,['product.id','product.sort','product.name','product.thumb','product.spec','product.price','product.market_price','product.stock']);
 		// 获取数据
 		$data['total']				= $Paginator->total();
 		$data['current_page']		= $Paginator->currentPage();

+ 1 - 0
app/Http/Requests/Admin/Product.php

@@ -29,6 +29,7 @@ class Product extends BaseRequest
         'add'                   => [],
         'edit'                  => ['id'],
         'set_status'            => ['id','status'],
+        'set_sort'              => ['id'],
 	];
 
     /**

+ 1 - 1
app/Http/Requests/Api/Custom.php

@@ -20,7 +20,7 @@ class Custom extends BaseRequest
             // 有时候我们希望某个字段在第一次验证失败后就停止运行验证规则,只需要将 bail 添加到规则中:
             // 验证字段,验证规则,提示信息
             // 地址
-            'city'                  => 'required|max:10',
+            'city'                  => 'required|max:15',
         ];
     }
 

+ 7 - 1
resources/views/admin/orders/index.blade.php

@@ -13,6 +13,12 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	<div class="form-group col col-md-1" style="margin-right: 2px;">
 		<input type="text" class="form-control" name="order_code" value="{{request('order_code','')}}" maxlength="13" placeholder="请输入订单编号查询" />
 	</div>
+	<div class="form-group col col-md-1" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="custom_code" value="{{request('custom_code','')}}" placeholder="请输入客户编码查询" />
+	</div>
+	<div class="form-group col col-md-1" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="phone" value="{{request('phone','')}}" placeholder="请输入收件人号码查询" />
+	</div>
 	<div class="form-group col col-md-1" style="margin-right: 2px;">
 		<input type="text" class="form-control" name="product_code" value="{{request('product_code','')}}" placeholder="请输入产品编码查询" />
 	</div>
@@ -85,7 +91,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							</a>
 							@endif
 							@if( $a['status'] == 1 && check_auth('admin/orders/set_status') )
-							<a class="btn btn-sm btn-danger" href="{{url('admin/orders/set_status?'.http_build_query(['id'=>$a['id'],'status'=>4]))}}" title="取消">
+							<a class="delete btn btn-sm btn-danger " data-url="{{url('admin/orders/set_status?'.http_build_query(['id'=>$a['order_id'],'status'=>4]))}}" title="取消">
 								取消
 							</a>
 							@endif

+ 36 - 1
resources/views/admin/product/index.blade.php

@@ -39,6 +39,7 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 						<th>产品库存</th>
 						<th>产品状态</th>
 						<th>生产厂家</th>
+						<th>排序</th>
 						<th>创建人</th>
 						<th>创建时间</th>
 						<th>操作</th>
@@ -54,6 +55,13 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 						<td> {{$a['stock']}} </td>
 						<td> {{$a['status']?'已下架':'已上架'}} </td>
 						<td> {{$a['producer_name']}}</td>
+						<td> 
+							@if(check_auth('admin/product/set_sort'))
+							<input type="text" class="set_sort" id="{{$a['id']}}" value="{{$a['sort']}}">
+							@else
+								{{$a['sort']}}
+							@endif
+						</td>
 						<td> {{$a['admin_name']}}</td>
 						<td> {{date('Y/m/d H:i:s',$a['insert_time'])}}</td>
 						<td>
@@ -79,9 +87,36 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 						<td colspan="20">总计 {{$list->total()}} 个产品</td>
 					</tr>
 				</tbody>
-
 			</table>
 		</div>
 	</div>
 </div>
+@endsection
+@section('javascript')
+<script>
+	$(function(){
+		$('.set_sort').change(function(){
+			var id = $(this).attr('id');
+			var sort = $(this).val();
+			$.ajax({
+				type: 'get',
+				url: "{{url('admin/product/set_sort')}}",
+				data: {id:id,sort:sort},
+				dataType: 'json',
+				success: function(data) {
+					art_dialog(data);
+				},
+				error: function(data) {
+					art.dialog({
+						content: data.responseJSON.message,
+						lock: true,
+						ok: function() {
+							
+						}
+					});
+				}
+			});
+		})
+	})
+</script>
 @endsection

+ 2 - 0
routes/web.php

@@ -115,6 +115,8 @@ Route::middleware('admin')->prefix('admin')->group(function(){
     Route::any('product/get_spec_html',[App\Http\Controllers\Admin\Product::class,'get_spec_html']);
     // 状态
     Route::any('product/get_sku_html',[App\Http\Controllers\Admin\Product::class,'get_sku_html']);
+    // 状态
+    Route::any('product/set_sort',[App\Http\Controllers\Admin\Product::class,'set_sort']);
 
 
     /* 客户管理 */