Commit a084214a by 庄欣

套系

parent 9b8f8c39
......@@ -7,4 +7,5 @@ class Cates extends Model
{
use \App\Traits\Models;
protected $table = "myp_category";
}
\ No newline at end of file
<?php
namespace App\City\Controller;
use Illuminate\Routing\Controller;
use App\City\Model\City as CityModel;
use App\Http\Response\Response;
class City extends Controller
{
use \App\Traits\Controller;
protected $query_fields = [
"is_open","is_hot","father"
];
public function index()
{
$query = request()->query();
$where = $this->filter($query);
$model = CityModel::where($where);
if (isset($where['city_name'])) {
$model->where($where,"like",$where['city_name']."%");
}
$res = $model->get();
return Response::success($res->toArray());
}
}
<?php
/**
* Created by PhpStorm.
* User: zhuangxin
* Date: 16-9-20
* Time: 下午2:09
*/
namespace App\City\Model;
use Illuminate\Database\Eloquent\Model;
class City extends Model
{
protected $table = "myp_city";
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: zhuangxin
* Date: 16-9-20
* Time: 下午2:24
*/
namespace App\City\Model;
use Illuminate\Database\Eloquent\Model;
class Travel extends Model
{
protected $table = "myp_travel_site";
}
\ No newline at end of file
......@@ -31,11 +31,11 @@ class Response
}
//while error occured return
public static function error($message = "操作失败" ,$code = HttpStatus::HttpInvalidArgument)
public static function error($message = "",$code = HttpStatus::HttpInvalidArgument)
{
return [
'code' => $code,
'message' => $message,
'message' => empty($message)?"操作失败":$message,
'api_ver' => RouteServiceProvider::getVersion()
];
}
......
......@@ -5,20 +5,32 @@ use Illuminate\Support\Facades\Validator;
class ValidatorBase extends Validator
{
protected $validator = [];
protected $message = [];
protected static $result;
//加_以免和父类重名
protected $_message = [];
public static $_validator;
public static $_result;
/**
* @return \Illuminate\Validation\Validator
*/
public function validate(array $post)
{
self::$result = self::make($post,$this->validator,$this->message);
if (method_exists($this,"custom_validate")) {
call_user_func_array([$this,"custom_validate"],[$post]);
self::$_validator = self::make($post,$this->validator,$this->message);
if (self::$_validator->passes()) {
if (method_exists($this, "custom_validate")) {
$res = call_user_func_array([$this, "custom_validate"], [$post]);
if (!empty($res)) {
$this->_message = $res;
self::$_result = false;
} else {
self::$_result = true;
}
} else {
self::$_result = true;
}
} else {
self::$_result = true;
}
return self::$result;
return self::$_result;
}
/**
......@@ -27,11 +39,14 @@ class ValidatorBase extends Validator
public function getMessages()
{
$messages = [];
if (self::$result->fails()) {
foreach (self::$result->messages()->toArray() as $message) {
if (self::$_result == false) {
foreach(self::$_validator->messages()->toArray() as $message) {
$messages = array_merge($messages,$message);
}
return array_merge($messages,$this->_message);
} else {
return [];
}
return $messages;
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ class AppServiceProvider extends ServiceProvider
//注册自定义验证
//汉字字符串长度
Validator::extend('chinese_lenth', function($attribute, $value, $parameters, $validator) {
Validator::extend('chinese_length', function($attribute, $value, $parameters, $validator) {
$strlen = mb_strlen($value,'utf8');
return ($strlen >= $parameters[0] && $strlen <= $parameters[1]);
});
......
......@@ -18,7 +18,8 @@ class EventServiceProvider extends ServiceProvider
\App\Works\Listeners\WorksSearcherListener::class
],
\App\Sets\Events\SetsEditedEvent::class => [
\App\Sets\Listeners\SetsSearcherListener::class
\App\Sets\Listeners\SetsSearcherListener::class,
\App\Sets\Listeners\SetsEditedListener::class
],
\App\Article\Events\ArtAddEvent::class => [
\App\Article\Listeners\ArtListener::class
......
<?php
/**
* Created by PhpStorm.
* User: zhuangxin
* Date: 16-9-13
* Time: 下午5:01
*/
namespace App\Sets\Listeners;
use App\Libraries\ElasticSearch\Search;
use App\Sets\Events\SetsEditedEvent;
use App\Member\Model\UserModel;
class SetsEditedListener
{
public function handle(SetsEditedEvent $event)
{
$model = $event->model;
/**
*修改促销信息等等
*/
$searcher = Search::getSearcher();
if($model->is_del == 0 && $model->is_shelf == $model::SHELF_UP && $model->exists == true) {
//修改而非新增
if ($model->wasRecentlyCreated == false) {
if ($model->is_promotion == 1)
{
}
}
}
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ namespace App\Sets\Listeners;
use App\Libraries\ElasticSearch\Search;
use App\Sets\Events\SetsEditedEvent;
use App\Member\Model\UserModel;
use App\Member\Model\User as UserModel;
class SetsSearcherListener
{
......@@ -42,8 +42,8 @@ class SetsSearcherListener
'sets_id' => $model->id,
'title' => $model->title,
'kw' => $keyworks,
'photographer_name' => getPhotographer($model->uid),
'lasttime' => date("Y-m-d H:i:s",NOW_TIME),
'photographer_name' => UserModel::getUserInfo($model->uid)->nickname,
'lasttime' => date("Y-m-d H:i:s",time()),
'is_promotion' => $model->is_promotion,
'start_time'=> $model->start_time,
'end_time' => $model->end_time,
......
......@@ -7,9 +7,28 @@
*/
namespace App\Sets\Model;
use App\Traits\Models;
use \Illuminate\Database\Eloquent\Model;
class Attachment extends Model
{
use Models;
protected $table = "myp_sets_attachment";
public $timestamps = false;
protected $fillable = [
"title","count","spec"
];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->beforeValidationOnCreate();
}
public function beforeValidationOnCreate()
{
$this->is_del = 0;
}
}
\ No newline at end of file
......@@ -7,13 +7,38 @@
*/
namespace App\Sets\Model;
use App\Cates\Model\Cates;
use App\Traits\Models;
use \Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use Models;
protected $table = "myp_sets_category";
const fields = [
"id","category_id","category_name"
];
public $timestamps = false;
protected $fillable = [
"category_id"
];
public function __construct(array $attributes = [])
{
{
parent::__construct($attributes);
if (isset($attributes['category_id']) && $attributes['category_id'] > 0) {
$id = $attributes['category_id'];
$this->category_name = Cates::where("id",$id)->first()->category_name;
}
$this->beforeValidationOnCreate();
}
}
public function beforeValidationOnCreate()
{
$this->is_del = 0;
}
}
\ No newline at end of file
<?php
namespace App\Sets\Model;
use \Illuminate\Database\Eloquent\Model;
class Comments extends Model
{
protected $table = "";
}
\ No newline at end of file
<?php
namespace App\Sets\Model;
use App\Traits\Models;
use \Illuminate\Database\Eloquent\Model;
class Keywords extends Model
{
use Models;
protected $table = "myp_sets_kw";
const fields = [
"id","kw_id","kw_name"
];
public $timestamps = false;
protected $fillable = [
"kw_id"
];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
if (isset($attributes['kw_id']) && $attributes['kw_id'] > 0) {
$id = $attributes['kw_id'];
$this->kw_name = \App\Kw\Model\Keywords::where("id",$id)->first()->kw_name;
}
$this->beforeValidationOnCreate();
}
public function beforeValidationOnCreate()
{
$this->is_del = 0;
}
}
\ No newline at end of file
......@@ -8,9 +8,40 @@
namespace App\Sets\Model;
use App\Traits\Models;
use \Illuminate\Database\Eloquent\Model;
class Promotion extends Model
{
use Models;
protected $table = "myp_sets_promotion";
protected $fillable = [
"promotion_price","promotion_start_time","promotion_end_time",
"per_user_count", "city_id"
];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->beforeValidationOnCreate();
}
public function beforeValidationOnCreate()
{
$this->is_del = 0;
$this->sort = 0;
$this->p_cost_count = 0;
$this->p_lock = 0;
$this->p_sale = 0;
$this->p_total_sale = 0;
}
public static function updated($callback, $priority = 0)
{
parent::updated(function(){
}, $priority);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace App\Sets\Model;
use App\Sets\Model\Category;
use \Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\DB;
......@@ -14,7 +15,15 @@ class Sets extends Model
protected $table = "myp_sets";
public $timestamps = false;
public function __construct(array $attributes)
protected $fillable = [
'title', 'cover', 'price', 'photographers_count', 'makeup_count', 'logistics_count', 'join_count', 'duration',
'negative_count', 'modification_count', 'modification_price', 'modeling_count', 'deadline_of_day',
'n_cost', 'start_time', 'end_time', 'type', 'abroad', 'uid', 'duration_unit', 'negative_give_all', 'service_city_id',
'service_city_name', 'is_shelf', 'change_descr', 'other_descr', 'travel_city_id', 'travel_city_name',
'abroad', 'modeling_count_from_user','is_promotion',"temp_price","type"
];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->beforeValidationOnCreate();
......@@ -29,16 +38,13 @@ class Sets extends Model
$this->makeup_descr = "";
$this->scene_descr = "";
$this->use_score = 0;
$this->cost_count = 0;
$this->n_order_count = 0;
$this->n_lock = 0;
$this->n_sale = 0;
$this->total_sale = 0;
$this->n_total_sale = 0;
$this->promotion_id = 0;
$this->total_sale = 0;
$this->p_lock = 0;
$this->create_time = date("Y-m-d H:i:s",time());
$this->is_del = 0;
$this->sort = 0;
}
public function relation_promotion()
......@@ -71,15 +77,94 @@ class Sets extends Model
return $this->hasMany(Comments::class,"sets_id")->where('is_del',0);
}
/**
* 新增
* return SetsModel | bool
*/
public static function newSets($data)
{
DB::beginTransaction();
$model = new self;
try {
$data['temp_price'] = $data['price'];
$model->fill($data)->save();
//促销
if (isset($data['promotion'])) {
$models = Promotion::add($data['promotion']);
$model->relation_promotion()->saveMany($models);
};
//绑定的样片
if (isset($data['works'])) {
$models = Works::add($data['works']);
$model->relation_works()->saveMany($models);
};
//输入的附件
if (isset($data['attachment'])) {
$models = Attachment::add($data['attachment']);
$model->relation_attatchment()->saveMany($models);
};
//分类
if (isset($data['category'])) {
$models = Category::add($data['category']);
$model->relation_category()->saveMany($models);
};
//关键词
if (isset($data['keywords'])) {
$models = Keywords::add($data['keywords']);
$model->relation_keywords()->saveMany($models);
};
} catch (\Exception $e) {
self::throwError($e);
DB::rollback();
return false;
}
DB::commit();
return $model;
}
public function uptSets($data)
{
DB::beginTransaction();
$model = new self;
try {
$data['temp_price'] = $data['price'];
$model->update($data);
//促销
if (isset($data['promotion'])) {
$models = Promotion::add($data['promotion']);
$model->relation_promotion()->delete();
$model->relation_promotion()->saveMany($models);
};
//绑定的样片
if (isset($data['works'])) {
$models = Works::add($data['works']);
$model->relation_works()->delete();
$model->relation_works()->saveMany($models);
};
//输入的附件
if (isset($data['attachment'])) {
$models = Attachment::add($data['attachment']);
$model->relation_attatchment()->delete();
$model->relation_attatchment()->saveMany($models);
};
//分类
if (isset($data['category'])) {
$models = Category::add($data['category']);
$model->relation_category()->delete();
$model->relation_category()->saveMany($models);
};
//关键词
if (isset($data['keywords'])) {
$models = Keywords::add($data['keywords']);
$model->relation_keywords()->delete();
$model->relation_keywords()->saveMany($models);
};
} catch (\Exception $e) {
self::throwError($e);
DB::rollback();
return false;
}
DB::commit();
return true;
}
}
\ No newline at end of file
......@@ -8,9 +8,28 @@
namespace App\Sets\Model;
use App\Traits\Models;
use \Illuminate\Database\Eloquent\Model;
class Works extends Model
{
use Models;
protected $table = "myp_sets_works";
protected $fillable = [
"works_id","sets_id"
];
public $timestamps = false;
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->beforeValidationOnCreate();
}
public function beforeValidationOnCreate()
{
$this->create_time = date("Y-m-d H:i:s",time());
$this->is_del = 0;
$this->is_hidden = 0;
}
}
\ No newline at end of file
......@@ -23,9 +23,23 @@ class SetsValidator extends Validator
'modeling_count' => 'required|integer',
'deadline_of_day' => 'required|integer',
'n_cost' => 'required|min:1',
'start_time' => 'required',
'end_time' => 'required',
'start_time' => 'required|date',
'end_time' => 'required|date',
'type' => 'required|in:0,1',
'abroad' => 'required|in:0,1',
'uid' => 'required',
'duration_unit' => 'required|in:hour,day,week',
'negative_give_all' => 'required',
'service_city_id' => 'required',
'service_city_name' => 'required',
'is_shelf' => 'required|in:0,1',
'change_descr' => 'required',
'other_descr' => 'required',
'travel_city_id' => 'required',
'travel_city_name' => 'required',
'abroad' => 'required|in:0,1',
'modeling_count_from_user' => 'required|min:0',
'is_promotion' => "required|in:0,1"
];
protected $message = [
......@@ -56,9 +70,25 @@ class SetsValidator extends Validator
'modeling_count.integer' => '造型数量必须是数字',
'deadline_of_day.required' => '您还未填写交图天数',
'deadline_of_day.integer' => '交图天数必须是数字',
'n_cost' => '套系可约单数必须大于0',
'start_time' => '请填写开始时间',
'end_time' => '请填写开始时间'
'n_cost.required' => '套系可约单数必填',
'n_cost.min' => '套系可约单数必须大于0',
'start_time.required' => '请填写开始时间',
'end_time.required' => '请填写开始时间',
'type.required' => '必须选择为普通套系或旅拍套系',
'type.in' => '套系类型应为0或1',
'abroad.required' => '必须填写境内或境外',
'abroad.in' => '境内或境外应为0或1',
'change_descr.required' => '改期说明必填',
'other_descr.required' => '其它说明必填',
'service_city_id.required' => '所属城市ID必填',
'travel_city_id.required' => '旅拍城市ID必填',
'service_city_name.required' => '所属城市名称必填',
'travel_city_name.required' => '旅拍城市名称必填',
'modeling_count_from_user.required' => '允许用户自带必填',
'negative_give_all.required' => '摄影师提供数必填',
'is_shelf.required' => '上下架状态必填',
'is_promotion.required' => '促销状态必填',
'is_promotion.in' => '促销状态必须为0或1',
];
/**
......@@ -77,15 +107,6 @@ class SetsValidator extends Validator
if ($data['modeling_count'] < $data['modeling_count_from_user']) {
$messages[] = "摄影师最多提供数不可大于造型总数量";
}
//整形判断
if (isset($data["allow_self_take"])) {
if(empty($data["modeling_count_from_user"])) {
$messages[] = '您还未填写允许用户自带数量';
};
if(!is_integer($data["modeling_count_from_user"])) {
$messages[] = '自带数量是数字';
};
}
if ($data['start_time'] > $data['end_time']) {
$messages[] = "套系开始时间必须小于结束时间";
......@@ -142,8 +163,7 @@ class SetsValidator extends Validator
}
unset($validator);
}
self::$result->setCustomMessages($messages);
return empty($messages);
return $messages;
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ use App\Sets\Validation\SetsValidator;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use App\Sets\Events\SetsEditedEvent;
use Illuminate\Support\Facades\Event;
class Sets extends \Illuminate\Routing\Controller
{
......@@ -82,16 +83,15 @@ class Sets extends \Illuminate\Routing\Controller
$validator = new SetsValidator();
$post = $request->all();
$res = $validator->validate($post);
if ($res->fails()) {
$messages = $validator->getMessages();
return Response::error($messages,HttpStatus::HttpValidationFailed);
if ($res == false) {
return Response::error($validator->getMessages(),HttpStatus::HttpValidationFailed);
}
$model = SetsModel::newSets($post);
if ($model !== false) {
Event::fire(new SetsEditedEvent($model));
return Response::ok();
} else {
return Response::error();
return Response::error(SetsModel::getError());
}
}
......
......@@ -12,6 +12,9 @@ trait Controller
*/
public function filter($where)
{
if (is_null($where) || empty($where)) {
return [];
}
require __DIR__."/../Functions/underscore.php";
$query_fields = null;
isset($this->query_fields) && $query_fields = $this->query_fields;
......
......@@ -4,6 +4,8 @@ namespace App\Traits;
Trait Models
{
static $error;
public function getRelate($relations)
{
is_string($relations) && $relations = explode(",",$relations);
......@@ -25,4 +27,32 @@ Trait Models
return static::get(["id"])->count();
}
public static function add(array $data)
{
$items = [];
foreach ($data as $item) {
$item = new self($item);
array_push($items,$item);
}
return $items;
}
public static function throwError($msg)
{
if ($msg instanceof \Exception) {
self::$error = [
'file' => $msg->getFile(),
'line' => $msg->getLine(),
'msg' => $msg->getMessage(),
];
} else {
self::$error = $msg;
}
}
public static function getError()
{
return json_encode(self::$error,JSON_UNESCAPED_SLASHES);
}
}
\ No newline at end of file
......@@ -2,9 +2,11 @@
namespace App\Works\Model;
use App\Traits\Models;
use \Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use Models;
protected $table = "myp_works_category";
}
\ No newline at end of file
<?php
namespace App\Works\Model;
use App\Traits\Models;
use \Illuminate\Database\Eloquent\Model;
class Keywords extends Model
{
use Models;
protected $table = "myp_works_kw";
const fields = [
"id","kw_id","kw_name"
];
}
\ No newline at end of file
......@@ -13,9 +13,9 @@ Route::group(["prefix" => "sets", 'namespace' => Provider::getNamespace("sets")]
//获取关联信息
Route::get ("/{id}/relation/{relation}" , "Sets@getRelate")->where(['id' => '\d+','relation'=>'\S+']);
//新增套系
/* Route::post("/" , "Sets@newsets");
Route::post("/" , "Sets@store");
//编辑套系
Route::put ("/{id}" , "Sets@update");
/*Route::put ("/{id}" , "Sets@update");
//软删除套系
Route::delete("/{id}", "Sets@softdelete");
//删除套系
......@@ -89,3 +89,9 @@ Route::group(["prefix" => "photo", 'namespace' => Provider::getNamespace("photo"
Route::delete("/{id}", "Photo@destory")->where(['id' => '\d+']);
Route::put("/{id}" , "Photo@update")->where(['id' => '\d+']);
});
//城市
Route::group(["prefix" => "city", 'namespace' => Provider::getNamespace("city")],function(){
Route::get("/" , "City@index");
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment