Consult.php 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','=',$infoNo];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  59. ->count();
  60. $total = ceil($count / $size);
  61. $page = $page >= $total ? $total : $page;
  62. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  63. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->order("a.id desc")->select();
  64. $data=[];
  65. foreach ($list as $value){
  66. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  67. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  68. true):[];
  69. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  70. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  71. $value['khname']="";
  72. if($value['khNo']!==""){
  73. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  74. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  75. }
  76. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  77. $data[]=$value;
  78. }
  79. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  80. }
  81. public function info(){
  82. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  83. if($id==""){
  84. return error_show(1002,"咨询单编号不能为空");
  85. }
  86. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  87. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  88. $fo['can']=$in;
  89. if(empty($fo)){
  90. return error_show(1002,"未找到咨询单编号");
  91. }else{
  92. return app_show(0,"获取成功",$fo);
  93. }
  94. }
  95. public function del(){
  96. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  97. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  98. if($de==false){
  99. return error_show(1002,'咨询单信息未找到');
  100. }
  101. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  102. if($dell){
  103. return error_show(0,"删除成功");
  104. }else
  105. return error_show(1002,"删除失败");
  106. }
  107. public function create(){
  108. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  109. if($is_project===""){
  110. return error_show(1002,"参数is_project不能为空");
  111. }
  112. if($is_project==1){
  113. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  114. if($projectNo===""){
  115. return error_show(1002,"参数projectNo不能为空");
  116. }
  117. }
  118. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  119. if($khNo===""){
  120. return error_show(1002,"参数khNo不能为空");
  121. }
  122. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  123. if($companyNo===""){
  124. return error_show(1002,"参数companyNo不能为空");
  125. }
  126. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  127. if($endtime===""){
  128. return error_show(1002,"参数endtime不能为空");
  129. }
  130. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  131. "";
  132. if($platform_code===""){
  133. return error_show(1002,"参数platform_code不能为空");
  134. }
  135. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  136. if($ladder==""){
  137. return error_show(1005,"参数ladder不能为空");
  138. }
  139. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  140. if($token==''){
  141. return error_show(105,"参数token不能为空");
  142. }
  143. $user =GetUserInfo($token);
  144. if(empty($user)||$user['code']!=0){
  145. return error_show(102,"用户数据不存在");
  146. }
  147. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  148. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  149. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  150. $zxNo=makeNo("ZX");
  151. Db::startTrans();
  152. try{
  153. $data=[
  154. "zxNo"=>$zxNo,
  155. "createrid"=>$createrid,
  156. "creater"=>$creater,
  157. "is_project"=>$is_project,
  158. "projectNo"=>isset($projectNo) ? $projectNo:"",
  159. "khNo"=>$khNo,
  160. "companyNo"=>$companyNo,
  161. "endtime"=>$endtime,
  162. "salesman"=>$creater,
  163. "platform_code"=>$platform_code,
  164. "saleid"=>$createrid,
  165. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  166. "status"=>0,
  167. "is_del"=>0,
  168. "addtime"=>date("Y-m-d H:i:s"),
  169. "updatetime"=>date("Y-m-d H:i:s"),
  170. ];
  171. $zx = Db::name("consult_order")->insert($data);
  172. if($zx){
  173. foreach ($ladder as $value){
  174. $infoNo=makeNo("IF");
  175. $specinfo=[];
  176. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  177. foreach ($value["specinfo"] as $v){
  178. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  179. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  180. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  181. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  182. $specinfo[]=$v;
  183. }
  184. }
  185. $info=[
  186. "infoNo"=>$infoNo,
  187. "zxNo"=>$zxNo,
  188. "spuCode"=>"",
  189. "good_name"=>$value['good_name'],
  190. "good_img"=>$value['good_img'],
  191. "cat_id"=>$value['cat_id'],
  192. "unit"=>$value['unit'],
  193. "brand_id"=>$value['brand_id'],
  194. "arrival_time"=>$value['arrival_time'],
  195. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  196. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  197. "is_addrs"=>$value['is_addrs'],
  198. "is_custom"=>$value['is_custom'],
  199. "metal_id"=>$value['metal_id'],
  200. "config"=>isset($value['config'])?$value['config']:"",
  201. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  202. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  203. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  204. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  205. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  206. "budget_price"=>$value['budget_price'],
  207. "num"=>$value['num'],
  208. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  209. "use_desc"=>$value['use_desc'],
  210. "remark"=>$value['remark'],
  211. "status"=>1,
  212. "is_del"=>0,
  213. "addtime"=>date("Y-m-d H:i:s"),
  214. "updatetime"=>date("Y-m-d H:i:s"),
  215. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  216. ];
  217. $up = Db::name("consult_info")->insert($info);
  218. if(!$up){
  219. Db::rollback();
  220. return error_show(1004,'添加失败');
  221. }else{
  222. //修改状态,添加待办
  223. ActionLog::logAdd($this->post['token'], [
  224. "order_code" => $infoNo,//咨询单详情编号
  225. "status" => 1,//这里的status是之前的值
  226. "action_remark" => '',//备注
  227. "action_type" => "create"//新建create,编辑edit,更改状态status
  228. ], "ZXD", 1, $info);
  229. ProcessOrder::AddProcess($this->post['token'], [
  230. "order_type" => 'ZXD',
  231. "order_code" => $infoNo,//咨询单详情编号
  232. "order_id" => 0,
  233. "order_status" => 1
  234. ]);
  235. }
  236. }
  237. $stn = ["order_code"=>$zxNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  238. ActionLog::logAdd($this->post['token'],$stn,"ZXD",2,$info);
  239. $process=["order_code"=>$zxNo,"order_id"=>Db::name("consult_order")->getLastInsID(),"order_status"=>1,"order_type"=>'ZXD'];
  240. ProcessOrder::AddProcess($this->post['token'],$process);
  241. Db::commit();
  242. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  243. }else{
  244. Db::rollback();
  245. return error_show(1004,"新建失败");
  246. }
  247. }catch (\Exception $e){
  248. Db::rollback();
  249. return error_show(1003,$e->getMessage());
  250. }
  251. }
  252. public function zxinfo(){
  253. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  254. if($infoNo==""){
  255. return error_show(1004,"参数infoNo不能为空");
  256. }
  257. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  258. if($zxinfo==false){
  259. return error_show(1004,"未找到信息数据");
  260. }
  261. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  262. if($zxorder==false){
  263. return error_show(1004,"未找到咨询信息数据");
  264. }
  265. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  266. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  267. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  268. $zxinfo['khname']="";
  269. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  270. $zxinfo['khNo']="";
  271. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  272. $zxinfo['brand']="";
  273. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  274. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  275. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  276. $zxinfo['company']="";
  277. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  278. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  279. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  280. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  281. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  282. $zxinfo['project_name']="";
  283. $zxinfo['budget_total']="";
  284. $zxinfo['departinfo']=[];
  285. $zxinfo['unit_name']="";
  286. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  287. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  288. if($zxorder['khNo']!==""){
  289. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  290. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  291. $zxinfo['khNo']= $zxorder['khNo'];
  292. }
  293. if($zxinfo['unit']!==""){
  294. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  295. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  296. }
  297. if($zxinfo['brand_id']!==""){
  298. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  299. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  300. }
  301. if($zxorder['companyNo']!==""){
  302. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  303. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  304. }
  305. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  306. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  307. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  308. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  309. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  310. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  311. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  312. }
  313. if($zxorder['depart']>0){
  314. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  315. }
  316. if($zxorder['platform_code']>0){
  317. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  318. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  319. }
  320. return app_show(0,"获取成功",$zxinfo);
  321. }
  322. public function zxedit(){
  323. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  324. if($infoNo==""){
  325. return error_show(1004,"参数infoNo不能为空");
  326. }
  327. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  328. if($zxinfo==false){
  329. return error_show(1004,"未找到信息数据");
  330. }
  331. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  332. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  333. if($good_name==""){
  334. return error_show(1003,"参数good_name不能为空");
  335. }
  336. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  337. if($good_img==""){
  338. return error_show(1003,"参数good_img不能为空");
  339. }
  340. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  341. if($cat_id==""){
  342. return error_show(1003,"参数cat_id不能为空");
  343. }
  344. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  345. if($unit==""){
  346. return error_show(1003,"参数unit不能为空");
  347. }
  348. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  349. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  350. if($arrival_time==""){
  351. return error_show(1003,"参数arrival_time不能为空");
  352. }
  353. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  354. if($specin==""){
  355. return error_show(1003,"参数specinfo不能为空");
  356. }
  357. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  358. // if($cost_desc==""){
  359. // return error_show(1003,"参数cost_desc不能为空");
  360. // }
  361. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  362. if($is_addrs===""){
  363. return error_show(1003,"参数is_addrs不能为空");
  364. }
  365. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  366. if($is_custom===""){
  367. return error_show(1003,"参数is_custom不能为空");
  368. }
  369. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  370. if($metal_id===""){
  371. return error_show(1003,"参数metal_id不能为空");
  372. }
  373. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  374. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  375. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  376. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  377. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  378. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  379. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  380. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  381. if($num===""){
  382. return error_show(1003,"参数num不能为空");
  383. }
  384. if($budget_price===""){
  385. return error_show(1003,"参数budget_price不能为空");
  386. }
  387. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  388. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  389. if($use_desc==""){
  390. return error_show(1003,"参数use_desc不能为空");
  391. }
  392. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  393. if($remark==""){
  394. return error_show(1003,"参数remark不能为空");
  395. }
  396. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  397. if($endtime==""){
  398. return error_show(1003,"参数endtime不能为空");
  399. }
  400. if($metal_id!=0){
  401. if($config==""){
  402. return error_show(1003,"参数config不能为空");
  403. }
  404. if($other_config==""){
  405. return error_show(1003,"参数other_config不能为空");
  406. }
  407. if($specs_weight===""){
  408. return error_show(1003,"参数specs_weight不能为空");
  409. }
  410. if($gold_price===""){
  411. return error_show(1003,"参数gold_price不能为空");
  412. }
  413. }
  414. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  415. if($token==''){
  416. return error_show(102,"参数token不能为空");
  417. }
  418. $user =GetUserInfo($token);
  419. if(empty($user)||$user['code']!=0){
  420. return error_show(105,"用户数据不存在");
  421. }
  422. $specinfo=[];
  423. foreach ($specin as $v){
  424. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  425. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  426. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  427. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  428. $specinfo[]=$v;
  429. }
  430. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  431. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  432. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  433. Db::startTrans();
  434. try{
  435. $innew =makeNo("IF");
  436. $info=[
  437. "infoNo"=>$innew,
  438. "zxNo"=>$zxinfo['zxNo'],
  439. "spuCode"=>"",
  440. "good_name"=>$good_name,
  441. "good_img"=>$good_img,
  442. "cat_id"=>$cat_id,
  443. "unit"=>$unit,
  444. "brand_id"=>$brand_id,
  445. "arrival_time"=>$arrival_time,
  446. "specinfo"=>json_encode($specinfo),
  447. // "color"=>$color,
  448. // "material"=>$material,
  449. "cost_desc"=>$cost_desc,
  450. "is_addrs"=>$is_addrs,
  451. "is_custom"=>$is_custom,
  452. "metal_id"=>$metal_id,
  453. "config"=>$config,
  454. "other_config"=>$other_config,
  455. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  456. "gold_price"=>$gold_price===""? 0 : $gold_price,
  457. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  458. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  459. "budget_price"=>$budget_price,
  460. "num"=>$num,
  461. "pgNo"=>$pgNo,
  462. "use_desc"=>$use_desc,
  463. "remark"=>$remark,
  464. "status"=>1,
  465. "is_del"=>0,
  466. "addtime"=>date("Y-m-d H:i:s"),
  467. "updatetime"=>date("Y-m-d H:i:s"),
  468. 'bargain_status'=>1,
  469. 'enclosure_file'=>$enclosure_file
  470. ];
  471. $up = Db::name("consult_info")->insert($info);
  472. if($up){
  473. //修改状态,添加待办
  474. ActionLog::logAdd($this->post['token'], [
  475. "order_code" => $innew,//咨询单详情编号
  476. "status" => 1,//这里的status是之前的值
  477. "action_remark" => '',//备注
  478. "action_type" => "create"//新建create,编辑edit,更改状态status
  479. ], "ZXD", 1, $info);
  480. ProcessOrder::AddProcess($this->post['token'], [
  481. "order_type" => 'ZXD',
  482. "order_code" => $innew,//咨询单详情编号
  483. "order_id" => 0,
  484. "order_status" => 1
  485. ]);
  486. if (!empty($bidlist)){
  487. foreach ($bidlist as $value){
  488. unset($value['id']);
  489. $value['infoNo']=$innew;
  490. $value['bidNo']=makeNo("BD");
  491. $value['spuCode']=makeNo("SKU");
  492. $value['status'] =0;
  493. $value['updatetime'] =date("Y-m-d H:i:s");
  494. $in = Db::name("consult_bids")->insert($value);
  495. if($in==false){
  496. Db::rollback();
  497. return error_show(1004,"反馈商品新建失败");
  498. }
  499. }
  500. }
  501. $zxinfo["bargain_status"] =1;
  502. $zxinfo["bargain_code"] =$innew;
  503. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  504. $bar=Db::name("consult_info")->save($zxinfo);
  505. if($bar==false){
  506. Db::rollback();
  507. return error_show(1004,"反馈商品更新失败");
  508. }else{
  509. //修改状态,添加待办
  510. ActionLog::logAdd($this->post['token'], [
  511. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  512. "status" => $zxinfo['status'],//这里的status是之前的值
  513. "action_remark" => '',//备注
  514. "action_type" => "edit"//新建create,编辑edit,更改状态status
  515. ], "ZXD", $zxinfo['status'], $zxinfo);
  516. // 并没有修改状态
  517. // ProcessOrder::AddProcess($this->post['token'], [
  518. // "order_type" => 'ZXD',
  519. // "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  520. // "order_id" => $zxinfo['id'],
  521. // "order_status" => $zxinfo['status']
  522. // ]);
  523. }
  524. //更新consule_order记录
  525. Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'updatetime'=>date('Y-m-d H:i:s')]);
  526. Db::commit();
  527. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  528. }
  529. }catch (\Exception $e){
  530. Db::rollback();
  531. return error_show(1004,$e->getMessage());
  532. }
  533. }
  534. //** 发布竞标任务 */
  535. public function bargain(){
  536. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  537. if($infoNo==""){
  538. return error_show(1004,"参数infoNo不能为空");
  539. }
  540. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  541. if($zxinfo==false){
  542. return error_show(1004,"未找到信息数据");
  543. }
  544. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  545. if($status===""){
  546. return error_show(1004,"参数status不能为空");
  547. }
  548. if($status==1&&$zxinfo['status']>1){
  549. $zxinfo['bargain_num']=+1;
  550. }
  551. $old_zxinfo_status = $zxinfo['status'];
  552. $zxinfo['status']=$status;
  553. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  554. $up = Db::name("consult_info")->save($zxinfo);
  555. if($up){
  556. //修改状态,添加待办
  557. ActionLog::logAdd($this->post['token'], [
  558. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  559. "status" => $old_zxinfo_status,//这里的status是之前的值
  560. "action_remark" => '',//备注
  561. "action_type" => "status"//新建create,编辑edit,更改状态status
  562. ], "ZXD", $zxinfo['status'], $zxinfo);
  563. ProcessOrder::AddProcess($this->post['token'], [
  564. "order_type" => 'ZXD',
  565. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  566. "order_id" => $zxinfo['id'],
  567. "order_status" => $zxinfo['status']
  568. ]);
  569. return app_show(0,"状态更新成功");
  570. }else{
  571. return error_show(1003,"状态更新失败");
  572. }
  573. }
  574. public function feadback(){
  575. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  576. if($infoNo==""){
  577. return error_show(1002,"参数infoNo不能为空");
  578. }
  579. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  580. if($zxinfo==false){
  581. return error_show(1003,"未找到信息数据");
  582. }
  583. if($zxinfo['status']!=1){
  584. return error_show(1004,"任务未进行");
  585. }
  586. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  587. if($zx==false){
  588. return error_show(1003,"未找咨询信息数据");
  589. }
  590. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  591. if($pname==""){
  592. return error_show(1002,"参数pname不能为空");
  593. }
  594. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  595. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  596. if($cat_id==""){
  597. return error_show(1002,"参数cat_id不能为空");
  598. }
  599. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  600. if($specin==""){
  601. return error_show(1003,"参数specinfo不能为空");
  602. }
  603. $specinfo=[];
  604. foreach ($specin as $v){
  605. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  606. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  607. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  608. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  609. $specinfo[]=$v;
  610. }
  611. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  612. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  613. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  614. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  615. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  616. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  617. :"";
  618. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  619. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  620. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  621. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  622. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  623. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  624. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  625. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  626. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  627. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  628. $good_weight = isset($this->post['good_weight'])&&$this->post['good_weight']!==""? floatval($this->post['good_weight']):"";
  629. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"";
  630. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"";
  631. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"";
  632. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval
  633. ($this->post['pakge_fee']):"";
  634. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  635. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"";
  636. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"";
  637. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"";
  638. if($nake_fee==="" ){
  639. return error_show(1004,"参数nake_fee不能为空");
  640. }
  641. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  642. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  643. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  644. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  645. if($token==''){
  646. return error_show(1002,"参数token不能为空");
  647. }
  648. $user =GetUserInfo($token);
  649. if(empty($user)||$user['code']!=0){
  650. return error_show(1005,"用户数据不存在");
  651. }
  652. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  653. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  654. $bidNo=makeNo("BD");
  655. $spucode=makeNo("SKU");
  656. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  657. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  658. //部分参数的大小校验
  659. $vali = Validate::rule([
  660. 'expire_day|有效时长'=>'require|elt:214748364',
  661. 'delivery_day|物流时长'=>'require|elt:214748364',
  662. 'work_day|生产工期'=>'require|elt:214748364',
  663. 'weight|总重量'=>'require|max:10',
  664. ]);
  665. $temp = [
  666. 'expire_day'=>$expire_day,
  667. 'delivery_day'=>$delivery_day,
  668. 'work_day'=>$work_day,
  669. 'weight'=>$weight,
  670. ];
  671. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  672. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  673. if($is_gold_price==1){
  674. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  675. ->find();
  676. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  677. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  678. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  679. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  680. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  681. $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  682. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  683. $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  684. }else{
  685. if($nake_fee){
  686. $saleprice = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee / (1 - $budget);
  687. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  688. }else{
  689. $saleprice = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee / (1 - $budget);
  690. $total_fee = $open_fee / $zxinfo['num'] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee;
  691. }
  692. }
  693. $data=[
  694. "bidNo"=>$bidNo,
  695. "infoNo"=>$infoNo,
  696. "zxNo"=>$zxinfo['zxNo'],
  697. "spuCode"=>$spucode,
  698. "good_name"=>$pname,
  699. "brand_id"=>$brandid,
  700. "cat_id"=>$cat_id,
  701. "specinfo"=>json_encode($specinfo),
  702. "unit_id"=>$unit_id,
  703. "cost_desc"=>$cost_desc,
  704. "work_day"=>$work_day,
  705. "delivery_day"=>$delivery_day,
  706. "good_img"=>$good_img,
  707. "expire_day"=>$expire_day,
  708. "origin_place"=>$origin_place,
  709. "supplierNo"=>$supplierNo,
  710. "pay_way"=>$pay_way,
  711. "tax"=>$tax,
  712. "send_way"=>$send_way,
  713. "metal_id"=>$metal_id,
  714. "is_gold_price"=>$is_gold_price,
  715. "config"=>$config,
  716. "other_config"=>$other_config,
  717. "weight"=>$weight,
  718. "good_weight"=>$good_weight,
  719. "is_diff"=>$is_diff,
  720. "demo_fee"=>$demo_fee,
  721. "delivery_fee"=>$delivery_fee,
  722. "open_fee"=>$open_fee,
  723. "pakge_fee"=>$pakge_fee,
  724. "nake_fee"=>$nake_fee,
  725. "mark_fee"=>$mark_fee,
  726. "cert_fee"=>$cert_fee,
  727. "cost_fee"=>$cost_fee,
  728. "total_fee"=>$total_fee,
  729. "supply_area"=>$supply_area,
  730. "remark"=>$remark,
  731. "sale_price"=>$saleprice,
  732. "sale_cost_fee"=>$sale_cost_fee,
  733. "origin_price"=>$saleprice,
  734. "createrid"=>$createrid,
  735. "creater"=>$creater,
  736. "status"=>$zxinfo['status']==1 ?1 :2,
  737. "is_del"=>0,
  738. "addtime"=>date("Y-m-d H:i:s"),
  739. "updatetime"=>date("Y-m-d H:i:s")
  740. ];
  741. Db::startTrans();
  742. try{
  743. $insert= Db::name("consult_bids")->insert($data);
  744. if($insert){
  745. // $data=[
  746. // "spuCode"=>$spucode,
  747. // "good_name"=>$pname,
  748. // "brand_id"=>$brandid,
  749. // "good_unit"=>$unit_id,
  750. // "good_type"=>0,
  751. // "moq"=>1,
  752. // "customized"=>$work_day,
  753. // "tax"=>$tax,
  754. // "supplierNo"=>$supplierNo,
  755. // "is_auth"=>0,
  756. // "craft_desc"=>$cost_desc,
  757. // "good_remark"=>$remark,
  758. // "good_img"=>$good_img,
  759. // "good_thumb_img"=>"",
  760. // "good_info_img"=>"",
  761. // "status"=>1,
  762. // "is_del"=>0,
  763. // "createrid"=>$createrid,
  764. // "creater"=>$creater,
  765. // "addtime"=>date("Y-m-d H:i:s"),
  766. // "updatetime"=>date("Y-m-d H:i:s")
  767. // ];
  768. // $good = Db::name("good_zixun")->insert($data);
  769. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  770. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  771. if($projectinfo==false){
  772. Db::rollback();
  773. return error_show(1006,"未找到项目信息");
  774. }
  775. $temp=[];
  776. $temp['spuCode']=$spucode;
  777. $temp['skuCode']="";
  778. $temp['pgNo']=$zxinfo['pgNo'];
  779. $temp['projectNo']=$zx['projectNo'];
  780. $temp['good_name']=$pname;
  781. $temp['good_type']=$projectinfo['good_type'];
  782. $temp['data_source']=2;
  783. $temp['cat_id']=$cat_id;
  784. $temp['budget_price']=$projectinfo['budget_price'];
  785. $temp['sale_price']=$saleprice;
  786. $temp['origin_price']=$total_fee;
  787. $temp['num']=$zxinfo['num'];
  788. $temp['status']=0;
  789. $temp['is_del']=0;
  790. $temp['creater']=$creater;
  791. $temp['createrid']=$createrid;
  792. $temp['addtime']=date("Y-m-d H:i:s");
  793. $temp['updatetime']=date("Y-m-d H:i:s");
  794. $nu = Db::name("project_feedback")->insert($temp);
  795. if($nu==false){
  796. Db::rollback();
  797. return error_show(1006,"项目反馈失败");
  798. }else{
  799. $old_projectinfo_status = $projectinfo['status'];
  800. $projectinfo['status']=2;
  801. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  802. $up = Db::name("project_info")->save($projectinfo);
  803. if($up){
  804. //修改状态,添加待办,只记录动作
  805. ActionLog::logAdd($this->post['token'], [
  806. "order_code" => $projectinfo['pgNo'],//编码
  807. "status" => $old_projectinfo_status,//这里的status是之前的值
  808. "action_remark" => '',//备注
  809. "action_type" => "status"//新建create,编辑edit,更改状态status
  810. ], "PRO", 2, $projectinfo);
  811. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  812. ->count();
  813. if($count==0){
  814. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  815. if($projetc!=false){
  816. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  817. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  818. if($proc==false){
  819. Db::rollback();
  820. return error_show(1006,"项目反馈失败");
  821. }else{
  822. //修改状态,添加待办
  823. ActionLog::logAdd($this->post['token'], [
  824. "order_code" => $projetc['projectNo'],//项目编码
  825. "status" => 1,//这里的status是之前的值
  826. "action_remark" => '',//备注
  827. "action_type" => "status"//新建create,编辑edit,更改状态status
  828. ], "PRO", 2, $projetc);
  829. ProcessOrder::AddProcess($this->post['token'], [
  830. "order_type" => 'PRO',
  831. "order_code" => $projetc['projectNo'],
  832. "order_id" => $projetc['id'],
  833. "order_status" => 2
  834. ]);
  835. }
  836. }
  837. }
  838. }
  839. }
  840. }
  841. Db::commit();
  842. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  843. }else{
  844. Db::rollback();
  845. return error_show(1006,"反馈失败");
  846. }
  847. }catch (\Exception $e){
  848. Db::rollback();
  849. return error_show(1006,$e->getMessage());
  850. }
  851. }
  852. public function feadinfo(){
  853. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  854. if($bidNo==""){
  855. return error_show(1004,"参数bidNo不能为空");
  856. }
  857. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  858. if($info==false){
  859. return error_show(1004,"未找到商品数据");
  860. }
  861. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  862. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  863. $info['cat_info'] = made($info['cat_id'],[]);
  864. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  865. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  866. if($info['brand_id']!=0){
  867. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  868. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  869. }else{
  870. $info["brand_name"]="";
  871. $info["brand_id"]="";
  872. }
  873. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  874. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  875. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  876. $god=[
  877. "metal_id"=>$info['metal_id'],
  878. "weight"=>$info["weight"],
  879. "demo_fee"=>$info["demo_fee"],
  880. "delivery_fee"=>$info["delivery_fee"],
  881. "open_fee"=>$info["open_fee"],
  882. "packing_fee"=>$info["pakge_fee"],
  883. "mark_fee"=>$info["mark_fee"],
  884. "nake_fee"=>$info["nake_fee"],
  885. "cert_fee"=>$info["cert_fee"],
  886. "cost_fee"=>$info["cost_fee"],
  887. "num"=>$bidinfo["num"],
  888. ];
  889. if($info['is_gold_price']==1){
  890. $price = GoldPrice($god, $budget/100);
  891. $info['sale_price'] =round($price,2);
  892. }
  893. $info['specinfo'] = json_decode($info['specinfo'],true);
  894. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  895. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  896. $info['bargain'] =$bargain;
  897. return app_show(0,"获取成功",$info);
  898. }
  899. public function feededit(){
  900. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  901. if($bidNo==""){
  902. return error_show(1002,"参数bidNo不能为空");
  903. }
  904. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  905. if($bidinfo==false){
  906. return error_show(1003,"未找到信息数据");
  907. }
  908. if($bidinfo['status']>=5){
  909. return error_show(1004,"咨询单已确认无法修改");
  910. }
  911. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  912. if($zxinfo==false){
  913. return error_show(1003,"未找到信息数据");
  914. }
  915. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  916. if($zx==false){
  917. return error_show(1003,"未找咨询信息数据");
  918. }
  919. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  920. if($pname==""){
  921. return error_show(1002,"参数pname不能为空");
  922. }
  923. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  924. // if($brandid==""){
  925. // return error_show(1002,"参数brandid不能为空");
  926. // }
  927. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  928. if($cat_id==""){
  929. return error_show(1002,"参数cat_id不能为空");
  930. }
  931. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  932. if($specin==""){
  933. return error_show(1003,"参数specinfo不能为空");
  934. }
  935. $specinfo=[];
  936. foreach ($specin as $v){
  937. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  938. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  939. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  940. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  941. $specinfo[]=$v;
  942. }
  943. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  944. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  945. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  946. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  947. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  948. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  949. :"";
  950. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  951. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  952. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  953. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  954. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  955. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"";
  956. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"";
  957. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  958. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  959. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"";
  960. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"";
  961. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"";
  962. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"";
  963. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"";
  964. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"";
  965. if($nake_fee==="" ||$nake_fee==0 ){
  966. return error_show(1004,"参数nake_fee不能为空或零");
  967. }
  968. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"";
  969. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"";
  970. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"";
  971. $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""? floatval($this->post['total_fee']):"";
  972. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  973. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  974. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  975. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  976. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  977. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  978. if($is_gold_price==1){
  979. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  980. ->find();
  981. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  982. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  983. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  984. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  985. $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  986. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  987. $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  988. }else{
  989. $saleprice = $open_fee/$zxinfo['num'] +
  990. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee/(1-$budget);
  991. $total_fee = $open_fee/$zxinfo['num'] +
  992. $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  993. }
  994. Db::startTrans();
  995. try{
  996. $data=[
  997. "good_name"=>$pname,
  998. "brand_id"=>$brandid,
  999. "cat_id"=>$cat_id,
  1000. "specinfo"=>json_encode($specinfo),
  1001. // "material"=>$material,
  1002. "unit_id"=>$unit_id,
  1003. "cost_desc"=>$cost_desc,
  1004. "work_day"=>$work_day,
  1005. "delivery_day"=>$delivery_day,
  1006. "good_img"=>$good_img,
  1007. "expire_day"=>$expire_day,
  1008. "origin_place"=>$origin_place,
  1009. "supplierNo"=>$supplierNo,
  1010. "pay_way"=>$pay_way,
  1011. "tax"=>$tax,
  1012. "send_way"=>$send_way,
  1013. "metal_id"=>$metal_id,
  1014. "is_gold_price"=>$is_gold_price,
  1015. "config"=>$config,
  1016. "other_config"=>$other_config,
  1017. "weight"=>$weight,
  1018. "is_diff"=>$is_diff,
  1019. "demo_fee"=>$demo_fee,
  1020. "delivery_fee"=>$delivery_fee,
  1021. "open_fee"=>$open_fee,
  1022. "pakge_fee"=>$pakge_fee,
  1023. "nake_fee"=>$nake_fee,
  1024. "mark_fee"=>$mark_fee,
  1025. "cert_fee"=>$cert_fee,
  1026. "cost_fee"=>$cost_fee,
  1027. "sale_cost_fee"=>$sale_cost_fee,
  1028. "total_fee"=>$total_fee,
  1029. "sale_price"=>$saleprice,
  1030. "supply_area"=>$supply_area,
  1031. "remark"=>$remark,
  1032. "updatetime"=>date("Y-m-d H:i:s")
  1033. ];
  1034. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1035. if($insert){
  1036. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1037. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1038. if($projectinfo==false){
  1039. Db::rollback();
  1040. return error_show(1006,"未找到项目信息");
  1041. }
  1042. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1043. if($feed==false){
  1044. Db::rollback();
  1045. return error_show(1006,"未找到项目反馈信息");
  1046. }
  1047. $feed['good_name']=$pname;
  1048. $feed['good_type']=$projectinfo['good_type'];
  1049. $feed['cat_id']=$cat_id;
  1050. $feed['sale_price']=$saleprice;
  1051. $feed['origin_price']=$total_fee;
  1052. $feed['updatetime']=date("Y-m-d H:i:s");
  1053. $temp['updatetime']=date("Y-m-d H:i:s");
  1054. $nu = Db::name("project_feedback")->save($feed);
  1055. if($nu==false){
  1056. Db::rollback();
  1057. return error_show(1006,"项目反馈失败");
  1058. }else{
  1059. $old_projectinfo_status = $projectinfo['status'];
  1060. $projectinfo['status']=2;
  1061. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1062. $up = Db::name("project_info")->save($projectinfo);
  1063. if($up){
  1064. //修改状态,添加待办,只记录动作
  1065. ActionLog::logAdd($this->post['token'], [
  1066. "order_code" => $projectinfo['pgNo'],//编码
  1067. "status" => $old_projectinfo_status,//这里的status是之前的值
  1068. "action_remark" => '',//备注
  1069. "action_type" => "status"//新建create,编辑edit,更改状态status
  1070. ], "PRO", 2, $projectinfo);
  1071. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1072. if ($count == 0) {
  1073. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1074. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1075. if ($project_id) {
  1076. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1077. if ($proc == false) {
  1078. Db::rollback();
  1079. return error_show(1006, "项目反馈失败");
  1080. }else{
  1081. //修改状态,添加待办
  1082. ActionLog::logAdd($this->post['token'], [
  1083. "order_code" => $projectinfo['projectNo'],//项目编码
  1084. "status" => 1,//这里的status是之前的值
  1085. "action_remark" => '',//备注
  1086. "action_type" => "status"//新建create,编辑edit,更改状态status
  1087. ], "PRO", 2, $this->post);
  1088. ProcessOrder::AddProcess($this->post['token'], [
  1089. "order_type" => 'PRO',
  1090. "order_code" => $projectinfo['projectNo'],
  1091. "order_id" => $project_id,
  1092. "order_status" => 2
  1093. ]);
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. }
  1100. Db::commit();
  1101. return app_show(0,"编辑成功");
  1102. }else{
  1103. Db::rollback();
  1104. return error_show(1004,"编辑失败");
  1105. }
  1106. }catch (\Exception $e){
  1107. Db::rollback();
  1108. return error_show(1004,$e->getMessage());
  1109. }
  1110. }
  1111. public function bargain_add(){
  1112. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1113. if($bidNo===""){
  1114. return error_show(1004,"参数bidNo不能为空");
  1115. }
  1116. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1117. if($info==false){
  1118. return error_show(1004,"未找到商品数据");
  1119. }
  1120. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1121. if($consult==false){
  1122. return error_show(1004,"未找到咨询数据");
  1123. }
  1124. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1125. if($bargain_price===""){
  1126. return error_show(1004,"参数bargain_price不能为空");
  1127. }
  1128. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1129. if($info['is_gold_price']==1){
  1130. if($cost_price==""){
  1131. return error_show(1004,"参数cost_price不能为空");
  1132. }
  1133. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1134. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1135. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1136. ->find();
  1137. $bargain_price = ($info['open_fee'] / $consult['num'] + $info['weight'] * $gold["price"] + $cost_price *$info['weight'] +
  1138. $info['pakge_fee'] + $info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1139. }
  1140. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1141. // if($bargain_reason===""){
  1142. // return error_show(1004,"参数bargain_reason不能为空");
  1143. // }
  1144. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1145. if($infos==false){
  1146. return error_show(1004,"未找到商品数据");
  1147. }
  1148. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1149. return error_show(1004,"咨询单招标未结束或已确认商品");
  1150. }
  1151. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1152. if($token==''){
  1153. return error_show(105,"参数token不能为空");
  1154. }
  1155. $user =GetUserInfo($token);
  1156. if(empty($user)||$user['code']!=0){
  1157. return error_show(1002,"用户数据不存在");
  1158. }
  1159. //新增两个字段
  1160. //议价备注
  1161. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1162. //议价原因id
  1163. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1164. if ($result_info_id != '') {
  1165. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1166. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1167. }
  1168. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1169. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1170. $bargainNo =makeNo("BA");
  1171. Db::startTrans();//::todo 金价 毛利计算
  1172. try{
  1173. $data=[
  1174. "bidsNo"=>$bidNo,
  1175. "infoNo"=>$info['infoNo'],
  1176. "zxNo"=>$info['zxNo'],
  1177. "bargainNo"=>$bargainNo,
  1178. "bargain_type"=>1,
  1179. "bargain_reason"=>$bargain_reason,
  1180. "sale_price"=>$info['sale_price'],
  1181. "cost_before_price"=>$info['cost_fee'],
  1182. "cost_after_price"=>$cost_price,
  1183. "before_rate"=>round(($info['sale_price']-$info['total_fee'])/$info['sale_price'],2),
  1184. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1185. "after_price"=>$bargain_price,
  1186. "exam_info"=>"",
  1187. "status"=>1,
  1188. "is_del"=>0,
  1189. "creater"=>$creater,
  1190. "createrid"=>$createrid,
  1191. "addtime"=>date("Y-m-d H:i:s"),
  1192. "updatetime"=>date("Y-m-d H:i:s"),
  1193. 'bargain_remark'=>$bargain_remark,
  1194. 'result_info_id'=>$result_info_id,
  1195. ];
  1196. $int = Db::name("bargain_order")->insert($data);
  1197. if($int){
  1198. $info['status']=3;
  1199. $info['updatetime']=date("Y-m-d H:i:s");
  1200. $up =Db::name("consult_bids")->save($info);
  1201. if($up){
  1202. $old_infos_status = $infos['status'];
  1203. $infos['status']=3;
  1204. $infos['updatetime']=date("Y-m-d H:i:s");
  1205. $ups =Db::name("consult_info")->save($infos);
  1206. if($ups){
  1207. //修改状态,添加待办
  1208. ActionLog::logAdd($this->post['token'], [
  1209. "order_code" => $infos['infoNo'],//咨询单详情编号
  1210. "status" => $old_infos_status,//这里的status是之前的值
  1211. "action_remark" => '',//备注
  1212. "action_type" => "status"//新建create,编辑edit,更改状态status
  1213. ], "ZXD", $infos['status'], $infos);
  1214. ProcessOrder::AddProcess($this->post['token'], [
  1215. "order_type" => 'ZXD',
  1216. "order_code" => $infos['infoNo'],//咨询单详情编号
  1217. "order_id" => $infos['id'],
  1218. "order_status" => $infos['status']
  1219. ]);
  1220. Db::commit();
  1221. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1222. }
  1223. }
  1224. }
  1225. Db::rollback();
  1226. return error_show(1004,"议价单新建失败");
  1227. }catch (\Exception $e){
  1228. Db::rollback();
  1229. return error_show(1004,$e->getMessage());
  1230. }
  1231. }
  1232. //选择商品
  1233. public function bids_check(){
  1234. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1235. if($bidNo===""){
  1236. return error_show(1004,"参数bidNo不能为空");
  1237. }
  1238. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1239. if($info==false){
  1240. return error_show(1004,"未找到商品数据");
  1241. }
  1242. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1243. if($infos==false){
  1244. return error_show(1004,"未找到商品数据");
  1245. }
  1246. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1247. return error_show(1004,"咨询单招标未结束或已确认商品");
  1248. }
  1249. Db::startTrans();
  1250. try {
  1251. $info['status']=6;
  1252. $info['updatetime']=date("Y-m-d H:i:s");
  1253. $bids = Db::name("consult_bids")->save($info);
  1254. if($bids){
  1255. $old_infos_status = $infos['status'];
  1256. $infos['status']=4;
  1257. $infos['updatetime']=date("Y-m-d H:i:s");
  1258. $se = Db::name("consult_info")->save($infos);
  1259. if($se){
  1260. //修改状态,添加待办
  1261. ActionLog::logAdd($this->post['token'], [
  1262. "order_code" => $infos['infoNo'],//咨询单详情编号
  1263. "status" => $old_infos_status,//这里的status是之前的值
  1264. "action_remark" => '',//备注
  1265. "action_type" => "status"//新建create,编辑edit,更改状态status
  1266. ], "ZXD", $infos['status'], $infos);
  1267. ProcessOrder::AddProcess($this->post['token'], [
  1268. "order_type" => 'ZXD',
  1269. "order_code" => $infos['infoNo'],//咨询单详情编号
  1270. "order_id" => $infos['id'],
  1271. "order_status" => $infos['status']
  1272. ]);
  1273. Db::commit();
  1274. return app_show(0,"商品确定成功");
  1275. }
  1276. }
  1277. Db::rollback();
  1278. return error_show(1004,"商品确认失败");
  1279. }catch (\Exception $e){
  1280. Db::rollback();
  1281. return error_show(1004,$e->getMessage());
  1282. }
  1283. }
  1284. //议价审核
  1285. public function bargain_status(){
  1286. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1287. if($bargainNo===""){
  1288. return error_show(1004,"参数bargainNo不能为空");
  1289. }
  1290. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1291. if($info==false){
  1292. return error_show(1004,"未找到议价数据");
  1293. }
  1294. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1295. if($bids==false){
  1296. return error_show(1004,"未找到商品数据");
  1297. }
  1298. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1299. if($coninfo==false){
  1300. return error_show(1004,"未找到咨询单数据");
  1301. }
  1302. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1303. if($status==''){
  1304. return error_show(1005,"参数status不能为空");
  1305. }
  1306. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1307. // if($remark==""){
  1308. // return error_show(1004,"参数remark不能为空");
  1309. // }
  1310. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1311. if($token==''){
  1312. return error_show(105,"参数token不能为空");
  1313. }
  1314. $user =GetUserInfo($token);
  1315. if(empty($user)||$user['code']!=0){
  1316. return error_show(1002,"用户数据不存在");
  1317. }
  1318. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1319. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1320. Db::startTrans();
  1321. try{
  1322. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1323. $examinfo[]=["status"=>$status,"remark"=>$remark,"createrid"=>$createrid,"creater"=>$creater];
  1324. $info['status'] =$status;
  1325. $info['remark'] =$remark;
  1326. $info['exam_info']=json_encode($examinfo) ;
  1327. $info['updatetime'] =date("Y-m-d H:i:s");
  1328. $up =Db::name("bargain_order")->save($info);
  1329. if($up){
  1330. if($status==5||$status==6||$status==7||$status==8){
  1331. $bids['status']=5;
  1332. if($status==8){
  1333. $bids['sale_price']=$info['after_price'];
  1334. if($bids['is_gold_price']==1){
  1335. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1336. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1337. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1338. ->find();
  1339. $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1340. $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1341. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1342. }
  1343. }
  1344. $bids['updatetime']=date("Y-m-d H:i:s");
  1345. $up =Db::name("consult_bids")->save($bids);
  1346. if($up==false){
  1347. Db::rollback();
  1348. return error_show(1004,"数据更新失败");
  1349. }
  1350. }
  1351. Db::commit();
  1352. return app_show(0,"更新成功");
  1353. }
  1354. }catch (\Exception $e){
  1355. Db::rollback();
  1356. return error_show(1004,$e->getMessage());
  1357. }
  1358. }
  1359. public function bargain_info(){
  1360. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1361. if($bargainNo===""){
  1362. return error_show(1004,"参数bargainNo不能为空");
  1363. }
  1364. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1365. if($info==false){
  1366. return error_show(1004,"未找到议价数据");
  1367. }
  1368. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1369. if($bidinfos==false){
  1370. return error_show(1004,"未找到商品数据");
  1371. }
  1372. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1373. ->find();
  1374. if($consultinfos==false){
  1375. return error_show(1004,"未找到咨询商品数据");
  1376. }
  1377. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1378. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1379. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1380. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1381. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1382. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_encode($info['exam_info']):"";
  1383. if($bidinfos['brand_id']!=0){
  1384. $info['brand_id'] = $bidinfos['brand_id'];
  1385. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1386. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1387. }else{
  1388. $info["brand_name"]="";
  1389. $info["brand_id"]="";
  1390. }
  1391. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1392. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1393. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1394. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1395. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1396. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1397. $info['budget'] =$budget;
  1398. $god=[
  1399. "metal_id"=>$bidinfos['metal_id'],
  1400. "weight"=>$bidinfos["weight"],
  1401. "demo_fee"=>$bidinfos["demo_fee"],
  1402. "delivery_fee"=>$bidinfos["delivery_fee"],
  1403. "open_fee"=>$bidinfos["open_fee"],
  1404. "packing_fee"=>$bidinfos["pakge_fee"],
  1405. "mark_fee"=>$bidinfos["mark_fee"],
  1406. "nake_fee"=>$bidinfos["nake_fee"],
  1407. "cert_fee"=>$bidinfos["cert_fee"],
  1408. "cost_fee"=>$bidinfos["cost_fee"],
  1409. "num"=>$bidinfoe["num"],
  1410. ];
  1411. $info['gold_price']=0;
  1412. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1413. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1414. ->find();
  1415. $info['gold_price'] =$gold['price'];
  1416. }
  1417. $info['cost_desc'] =$bidinfos['cost_desc'];
  1418. $info['work_day'] =$bidinfos['work_day'];
  1419. $info['delivery_day'] =$bidinfos['delivery_day'];
  1420. $info['expire_day'] =$bidinfos['expire_day'];
  1421. $info['origin_place'] =$bidinfos['origin_place'];
  1422. $info['origin_addr'] ="";
  1423. if($bidinfos['origin_place']!=''){
  1424. $code = explode(",",$bidinfos['origin_place']);
  1425. $temp=[];
  1426. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1427. $temp['city_code']=isset($code[1])?$code[1]:"";
  1428. $temp['area_code']=isset($code[2])?$code[2]:"";
  1429. $addr= GetAddr(json_encode($temp));
  1430. $info['origin_addr'] = $addr;
  1431. }
  1432. $info['supplierNo'] =$bidinfos['supplierNo'];
  1433. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1434. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1435. $info['pay_way'] =$bidinfos['pay_way'];
  1436. $info['tax'] =$bidinfos['tax'];
  1437. $info['send_way'] =$bidinfos['send_way'];
  1438. $info['metal_id'] =$bidinfos['metal_id'];
  1439. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1440. $info['config'] =$bidinfos['config'];
  1441. $info['other_config'] =$bidinfos['other_config'];
  1442. $info['weight'] =$bidinfos['weight'];
  1443. $info['is_diff'] =$bidinfos['is_diff'];
  1444. $info['demo_fee'] =$bidinfos['demo_fee'];
  1445. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1446. $info['open_fee'] =$bidinfos['open_fee'];
  1447. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1448. $info['nake_fee'] =$bidinfos['nake_fee'];
  1449. $info['mark_fee'] =$bidinfos['mark_fee'];
  1450. $info['cert_fee'] =$bidinfos['cert_fee'];
  1451. $info['cost_fee'] =$bidinfos['cost_fee'];
  1452. $info['total_fee'] =$bidinfos['total_fee'];
  1453. $info['supply_area'] =$bidinfos['supply_area'];
  1454. $info['remark'] =$bidinfos['remark'];
  1455. $info['is_addrs'] =$consultinfos['is_addrs'];
  1456. $info['is_custom'] =$consultinfos['is_custom'];
  1457. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1458. $info['sale_price'] =round($bidinfos['sale_price'],2);
  1459. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1460. //获取议价原因
  1461. if ($info['result_info_id'] != 0) {
  1462. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1463. } else {
  1464. $info['result_info'] = '';
  1465. }
  1466. return app_show(0,"获取成功",$info);
  1467. }
  1468. public function bidlist(){
  1469. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1470. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1471. $where=[['is_del',"=",0]];
  1472. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1473. if ($zxNo !== "") {
  1474. $where[] = ['zxNo','=',$zxNo];
  1475. }
  1476. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1477. if ($infoNo !== "") {
  1478. $where[] = ['infoNo','=',$infoNo];
  1479. }
  1480. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1481. if ($bidNo !== "") {
  1482. $where[] = ['bidNo','=',$bidNo];
  1483. }
  1484. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1485. if ($pgNo !== "") {
  1486. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1487. $where[] = ['infoNo','in',$bidinfo];
  1488. }
  1489. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1490. if ($bargain_status !== "") {
  1491. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1492. $where[] = ['infoNo','in',$bidinfo];
  1493. }
  1494. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1495. if ($projectNo !== "") {
  1496. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1497. ("zxNo");
  1498. $where[] = ['zxNo','in',$zxlist];
  1499. }
  1500. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1501. if($is_own==1){
  1502. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1503. if($token==""){
  1504. return error_show(101,'token不能为空');
  1505. }
  1506. $apply_id =GetUserInfo($token);
  1507. if(empty($apply_id)||$apply_id['code']!=0){
  1508. return error_show(1002,"申请人数据不存在");
  1509. }
  1510. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1511. $where[]=['createrid',"=",$rm];
  1512. }
  1513. $count = Db::name('consult_bids')->where($where)->count();
  1514. $total = ceil($count / $size);
  1515. $page = $page >= $total ? $total : $page;
  1516. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1517. $data=[];
  1518. foreach ($list as $value){
  1519. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1520. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1521. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1522. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1523. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1524. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1525. if($value['brand_id']!=0){
  1526. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1527. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1528. }else{
  1529. $value["brand_name"]="";
  1530. $value["brand_id"]="";
  1531. }
  1532. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1533. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1534. $god=[
  1535. "metal_id"=>$value['metal_id'],
  1536. "weight"=>$value["weight"],
  1537. "demo_fee"=>$value["demo_fee"],
  1538. "delivery_fee"=>$value["delivery_fee"],
  1539. "open_fee"=>$value["open_fee"],
  1540. "packing_fee"=>$value["pakge_fee"],
  1541. "mark_fee"=>$value["mark_fee"],
  1542. "nake_fee"=>$value["nake_fee"],
  1543. "cert_fee"=>$value["cert_fee"],
  1544. "cost_fee"=>$value["cost_fee"],
  1545. "num"=>$bidinfo["num"],
  1546. ];
  1547. if($value['is_gold_price']==1){
  1548. $price = GoldPrice($god, $budget/100);
  1549. $value['sale_price'] = round($price,2);
  1550. }
  1551. $value['specinfo'] = json_decode($value['specinfo'],true);
  1552. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1553. $value['bargain_status']=$bidinfo['bargain_status'];
  1554. //reject驳回原因,status==5表示驳回
  1555. $value['reject']=[];
  1556. if ($value['status'] == 5) {
  1557. $value['reject'] = Db::name('bargain_order')
  1558. ->field('id,remark,status')
  1559. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1560. ->whereIn('status', [5, 6])
  1561. ->find();
  1562. }
  1563. //产地
  1564. if($value['origin_place']!=''){
  1565. $code = explode(",",$value['origin_place']);
  1566. $temp=[];
  1567. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1568. $temp['city_code']=isset($code[1])?$code[1]:"";
  1569. $temp['area_code']=isset($code[2])?$code[2]:"";
  1570. $addr= GetAddr(json_encode($temp));
  1571. $value['origin_addr'] = $addr;
  1572. }
  1573. $data[] = $value;
  1574. }
  1575. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1576. }
  1577. public function feedlist(){
  1578. $where=[['is_del',"=",0]];
  1579. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1580. if ($zxNo !== "") {
  1581. $where[] = ['zxNo','=',$zxNo];
  1582. }
  1583. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1584. if ($infoNo !== "") {
  1585. $where[] = ['infoNo','=',$infoNo];
  1586. }
  1587. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1588. if ($bidNo !== "") {
  1589. $where[] = ['bidNo','=',$bidNo];
  1590. }
  1591. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1592. if ($projectNo !== "") {
  1593. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1594. ("zxNo");
  1595. $where[] = ['zxNo','in',$zxlist];
  1596. }
  1597. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1598. if($token==''){
  1599. return error_show(102,"参数token不能为空");
  1600. }
  1601. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1602. if($is_own==1){
  1603. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1604. if($token==""){
  1605. return error_show(101,'token不能为空');
  1606. }
  1607. $apply_id =GetUserInfo($token);
  1608. if(empty($apply_id)||$apply_id['code']!=0){
  1609. return error_show(1002,"申请人数据不存在");
  1610. }
  1611. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1612. $where[]=['createrid',"=",$rm];
  1613. }
  1614. $list =Db::name('consult_bids')->where($where)->select();
  1615. $data=[];
  1616. foreach ($list as $value){
  1617. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1618. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1619. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1620. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1621. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1622. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1623. if($value['brand_id']!=0){
  1624. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1625. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1626. }else{
  1627. $value["brand_name"]="";
  1628. $value["brand_id"]="";
  1629. }
  1630. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1631. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1632. $god=[
  1633. "metal_id"=>$value['metal_id'],
  1634. "weight"=>$value["weight"],
  1635. "demo_fee"=>$value["demo_fee"],
  1636. "delivery_fee"=>$value["delivery_fee"],
  1637. "open_fee"=>$value["open_fee"],
  1638. "packing_fee"=>$value["pakge_fee"],
  1639. "mark_fee"=>$value["mark_fee"],
  1640. "nake_fee"=>$value["nake_fee"],
  1641. "cert_fee"=>$value["cert_fee"],
  1642. "cost_fee"=>$value["cost_fee"],
  1643. "num"=>$bidinfo["num"],
  1644. ];
  1645. if($value['is_gold_price']==1){
  1646. $price = GoldPrice($god, $budget/100);
  1647. $value['sale_price'] =round($price,2);
  1648. }
  1649. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1650. $value['specinfo'] = json_decode($value['specinfo'],true);
  1651. $value['bargain_status']=$bidinfo['bargain_status'];
  1652. $data[]=$value;
  1653. }
  1654. return app_show(0,"获取成功",$data);
  1655. }
  1656. public function bragain_list(){
  1657. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1658. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1659. $where=[['is_del',"=",0]];
  1660. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1661. if($bidsNo!=""){
  1662. $where[]=["bidsNo","=",$bidsNo];
  1663. }
  1664. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1665. if ($zxNo !== "") {
  1666. $where[] = ['zxNo','=',$zxNo];
  1667. }
  1668. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1669. if ($infoNo !== "") {
  1670. $where[] = ['infoNo','=',$infoNo];
  1671. }
  1672. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1673. if ($projectNo !== "") {
  1674. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1675. ("zxNo");
  1676. $where[] = ['zxNo','in',$zxlist];
  1677. }
  1678. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1679. if ($pgNo !== "") {
  1680. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1681. $where[] = ['infoNo','in',$bidinfo];
  1682. }
  1683. $count=Db::name("bargain_order")->where($where)->count();
  1684. $total = ceil($count / $size);
  1685. $page = $page >= $total ? $total : $page;
  1686. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1687. $data=[];
  1688. foreach ($list as $value){
  1689. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1690. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1691. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1692. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1693. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1694. if($bidinfos['brand_id']!=0){
  1695. $value['brand_id'] = $bidinfos['brand_id'];
  1696. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1697. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1698. }else{
  1699. $value["brand_name"]="";
  1700. $value["brand_id"]="";
  1701. }
  1702. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1703. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1704. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1705. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1706. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1707. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1708. $value['budget'] =$budget;
  1709. $god=[
  1710. "metal_id"=>$bidinfos['metal_id'],
  1711. "weight"=>$bidinfos["weight"],
  1712. "demo_fee"=>$bidinfos["demo_fee"],
  1713. "delivery_fee"=>$bidinfos["delivery_fee"],
  1714. "open_fee"=>$bidinfos["open_fee"],
  1715. "packing_fee"=>$bidinfos["pakge_fee"],
  1716. "mark_fee"=>$bidinfos["mark_fee"],
  1717. "nake_fee"=>$bidinfos["nake_fee"],
  1718. "cert_fee"=>$bidinfos["cert_fee"],
  1719. "cost_fee"=>$bidinfos["cost_fee"],
  1720. "num"=>$bidinfoe["num"],
  1721. ];
  1722. // if($bidinfos['is_gold_price']==1){
  1723. // $price = GoldPrice($god, $budget/100);
  1724. // }else{
  1725. // $price = GoodPrice($god, $budget/100);
  1726. // }
  1727. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1728. $value['sale_price'] =round($bidinfos['sale_price'],2);
  1729. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1730. $data[]=$value;
  1731. }
  1732. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1733. }
  1734. public function crontablist(){
  1735. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1736. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1737. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1738. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1739. if ($zxNo !== "") {
  1740. $where[] = ['a.zxNo','=',$zxNo];
  1741. }
  1742. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1743. if ($salesman !== "") {
  1744. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1745. $where[]= ["b.salesman",'like',"%$salesman%"];
  1746. }
  1747. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1748. if ($cpName !== "") {
  1749. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1750. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1751. }
  1752. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1753. if ($khNo !== "") {
  1754. // $where['khNo'] = $khNo;
  1755. $where[]= ["b.khNo",'like',"%$khNo%"];
  1756. }
  1757. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1758. if ($start !="") {
  1759. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1760. $where[]= ["a.addtime",'>=',$start];
  1761. }
  1762. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1763. if($end !=""){
  1764. $where[]= ["a.addtime",'<=',$end];
  1765. }
  1766. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1767. if ($status !== "") {
  1768. $where[]= ["a.status",'=',$status];
  1769. }
  1770. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1771. ->count();
  1772. $total = ceil($count / $size);
  1773. $page = $page >= $total ? $total : $page;
  1774. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1775. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  1776. $data=[];
  1777. foreach ($list as $value){
  1778. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1779. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1780. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1781. $value['khname']="";
  1782. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1783. true):[];
  1784. if($value['khNo']!==""){
  1785. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1786. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1787. }
  1788. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1789. $data[]=$value;
  1790. }
  1791. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1792. }
  1793. }