Consult.php 121 KB

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